An infinite loop ... :(

This commit is contained in:
mikespook 2013-01-23 17:25:38 +08:00
parent f7a84a6587
commit 16a965f52d
3 changed files with 14 additions and 12 deletions

View File

@ -178,15 +178,12 @@ func (client *Client) read() (rel []byte, err error) {
// out loop // out loop
func (client *Client) outLoop() { func (client *Client) outLoop() {
ok := true for job := range client.out {
for ok {
if job, ok := <-client.out; ok {
if err := client.write(job.Encode()); err != nil { if err := client.write(job.Encode()); err != nil {
client.err(err) client.err(err)
} }
} }
} }
}
// in loop // in loop
func (client *Client) inLoop() { func (client *Client) inLoop() {
@ -353,7 +350,7 @@ func (client *Client) Echo(data []byte) (r []byte) {
// Close // Close
func (client *Client) Close() (err error) { func (client *Client) Close() (err error) {
close(client.in) // close(client.in)
close(client.out) close(client.out)
close(client.echo) close(client.echo)

View File

@ -11,6 +11,10 @@ func TestClientAddServer(t *testing.T) {
var err error var err error
if client, err = New("127.0.0.1:4730"); err != nil { if client, err = New("127.0.0.1:4730"); err != nil {
t.Error(err) t.Error(err)
return
}
client.ErrHandler = func(e error) {
t.Log(e)
} }
} }
@ -71,7 +75,6 @@ func TestClientStatus(t *testing.T) {
func TestClientClose(t *testing.T) { func TestClientClose(t *testing.T) {
return
if err := client.Close(); err != nil { if err := client.Close(); err != nil {
t.Error(err) t.Error(err)
} }

View File

@ -1,15 +1,17 @@
package client package client
import ( import (
"errors" // "errors"
"testing" // "testing"
) )
var ( var (
pool = NewPool() pool = NewPool()
) )
/*
func TestPoolAdd(t *testing.T) { func TestPoolAdd(t *testing.T) {
return
t.Log("Add servers") t.Log("Add servers")
if err := pool.Add("127.0.0.1:4730", 1); err != nil { if err := pool.Add("127.0.0.1:4730", 1); err != nil {
t.Error(err) t.Error(err)
@ -21,7 +23,7 @@ func TestPoolAdd(t *testing.T) {
t.Error(errors.New("2 servers expected")) t.Error(errors.New("2 servers expected"))
} }
} }
/*
func TestPoolEcho(t *testing.T) { func TestPoolEcho(t *testing.T) {
pool.JobHandler = func(job *Job) error { pool.JobHandler = func(job *Job) error {
echo := string(job.Data) echo := string(job.Data)
@ -43,10 +45,10 @@ func TestPoolDo(t *testing.T) {
t.Log(handle) t.Log(handle)
} }
} }
*/
func TestPoolClose(t *testing.T) { func TestPoolClose(t *testing.T) {
return return
if err := pool.Close(); err != nil { if err := pool.Close(); err != nil {
t.Error(err) t.Error(err)
} }
} }
*/