forked from iwanbk/gobeanstalk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pool_test.go
44 lines (37 loc) · 1.07 KB
/
pool_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package gobeanstalk
import "testing"
func newPool(t *testing.T) *Pool {
p, err := NewPool(address, 10)
if err != nil {
t.Fatal("NewPool failed.err = :", err.Error())
}
return p
}
func assertPoolLength(t *testing.T, fName string, poolLength int, expectedLength int) {
if poolLength != expectedLength {
t.Fatalf("%s failed.err = pool size of %d expected got %d", fName, poolLength, expectedLength)
}
}
func TestNewPool(t *testing.T) {
p, err := NewPool(address, 10)
if err != nil {
t.Fatal("NewPool failed.err = :", err.Error())
}
assertPoolLength(t, "NewPool", len(p.pool), 10)
// Test getting and using a pool member
conn, err := p.Get()
if err != nil {
t.Fatal("Pool.Get failed.Err = ", err.Error())
}
assertPoolLength(t, "PoolGet", len(p.pool), 9)
err = conn.Use(testtube)
if err != nil {
t.Fatal("Get (use) failed.Err = ", err.Error())
}
//Test releasing the connection back into the pool
p.Release(conn)
assertPoolLength(t, "Pool.Release", len(p.pool), 10)
// Test emptying the pool
p.Empty()
assertPoolLength(t, "Pool.Release", len(p.pool), 0)
}