-
Notifications
You must be signed in to change notification settings - Fork 0
/
pool_test.go
49 lines (42 loc) · 956 Bytes
/
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
package thrift_transport_pool
import (
"git.apache.org/thrift.git/lib/go/thrift"
"testing"
"time"
)
func Test_Pop(t *testing.T) {
pool := NewPool(1, "", func(hostPort string) (thrift.TTransport, error) {
return &MockTransport{}, nil
})
_, err := pool.Pop()
if err != nil {
t.Fatal("should pop")
}
if pool.CreatedCount != 1 {
t.Fatal("createdCount should eq 1")
}
}
func Test_Pop_WithTimeout(t *testing.T) {
pool := NewPool(1, "", func(hostPort string) (thrift.TTransport, error) {
return &MockTransport{}, nil
})
pool.TimeOut = time.Millisecond
pool.Pop()
_, err := pool.Pop()
if err != ErrPopTimeOut {
t.Fatal("should return ErrTimeOut")
}
}
func Test_Push(t *testing.T) {
pool := NewPool(1, "", func(hostPort string) (thrift.TTransport, error) {
return &MockTransport{}, nil
})
tr, err := pool.Pop()
if err != nil {
t.Fatal("should pop")
}
pool.Push(tr)
if len(pool.Pool) != 1 {
t.Fatal("should push")
}
}