fixed nil pointer
This commit is contained in:
parent
e5179e3b5b
commit
e3f789bc86
@ -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)
|
||||
|
@ -80,9 +80,11 @@ func (pool *Pool) Add(net, addr string, rate int) (err error) {
|
||||
} else {
|
||||
var client *Client
|
||||
client, err = New(net, addr)
|
||||
if err == nil {
|
||||
item = &poolClient{Client: client, Rate: rate}
|
||||
pool.clients[addr] = item
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user