-
Notifications
You must be signed in to change notification settings - Fork 18
/
pool_test.go
92 lines (82 loc) · 1.99 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package godis
import (
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func TestPool_Basic(t *testing.T) {
pool := NewPool(&PoolConfig{
MaxTotal: 4,
MaxIdle: 2,
MinIdle: 2,
TestOnBorrow: true,
}, &Option{
Host: "localhost",
Port: 6379,
ConnectionTimeout: 2 * time.Second,
SoTimeout: 2 * time.Second,
Password: "",
Db: 0,
})
redis, e := pool.GetResource()
assert.Nil(t, e)
s, e := redis.Echo("godis")
assert.Nil(t, e)
assert.Equal(t, "godis", s)
e = pool.returnResourceObject(redis)
assert.Nil(t, e)
s, e = redis.Echo("godis")
assert.Nil(t, e)
assert.Equal(t, "godis", s)
redis1, e := pool.GetResource()
assert.Nil(t, e)
e = pool.returnBrokenResourceObject(redis1)
assert.Nil(t, e)
s, e = redis1.Echo("godis")
assert.NotNil(t, e)
assert.Equal(t, "", s)
pool.internalPool.Clear(nil)
redis3, e := pool.GetResource()
assert.Nil(t, e)
pool.Destroy()
s, e = redis3.Echo("godis")
assert.Nil(t, e)
assert.Equal(t, "godis", s)
_, e = pool.GetResource()
assert.NotNil(t, e)
}
func TestPool_Basic2(t *testing.T) {
pool := NewPool(&PoolConfig{
MaxTotal: 4,
MaxIdle: 2,
MinIdle: 2,
MinEvictableIdleTime: 10,
TestOnBorrow: true,
}, &Option{
Host: "localhost",
Port: 6379,
ConnectionTimeout: 2 * time.Second,
SoTimeout: 2 * time.Second,
Password: "123456",
Db: 0,
})
_, e := pool.GetResource()
assert.NotNil(t, e) //auth error
}
func TestPool_Basic3(t *testing.T) {
pool := NewPool(&PoolConfig{
MaxTotal: 30,
MaxIdle: 20,
MinIdle: 10,
MinEvictableIdleTime: 10,
TestOnBorrow: true,
}, &Option{
Host: "localhost",
Port: 6380,
ConnectionTimeout: 2 * time.Second,
SoTimeout: 2 * time.Second,
Db: 0,
})
_, e := pool.GetResource()
assert.NotNil(t, e) //auth error
}