diff --git a/client/client_test.go b/client/client_test.go index 8057d61..1cbb48a 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -14,8 +14,7 @@ func TestClientAddServer(t *testing.T) { t.Log("Add local server 127.0.0.1:4730") var err error if client, err = New("tcp4", "127.0.0.1:4730"); err != nil { - t.Error(err) - return + t.Fatal(err) } client.ErrorHandler = func(e error) { t.Log(e) diff --git a/client/pool.go b/client/pool.go index 9c82a3d..3c8865a 100644 --- a/client/pool.go +++ b/client/pool.go @@ -80,8 +80,10 @@ func (pool *Pool) Add(net, addr string, rate int) (err error) { } else { var client *Client client, err = New(net, addr) - item = &poolClient{Client: client, Rate: rate} - pool.clients[addr] = item + if err == nil { + item = &poolClient{Client: client, Rate: rate} + pool.clients[addr] = item + } } return } diff --git a/client/pool_test.go b/client/pool_test.go index 51b00cf..bd3402f 100644 --- a/client/pool_test.go +++ b/client/pool_test.go @@ -10,14 +10,16 @@ var ( func TestPoolAdd(t *testing.T) { t.Log("Add servers") + c := 2 if err := pool.Add("tcp4", "127.0.0.1:4730", 1); err != nil { - t.Error(err) + t.Fatal(err) } if err := pool.Add("tcp4", "127.0.1.1:4730", 1); err != nil { - t.Error(err) + t.Log(err) + c -= 1 } - if len(pool.clients) != 2 { - t.Errorf("2 servers expected, %d got.", len(pool.clients)) + if len(pool.clients) != c { + t.Errorf("%d servers expected, %d got.", c, len(pool.clients)) } }