@@ -13,14 +13,15 @@ import (
13
13
"gitlab.myteksi.net/dbops/Redis/v8/internal/pool"
14
14
)
15
15
16
- func assertPoolStats (pooler pool.DynamicPooler , hits , misses , timeouts , totals , idles , stales uint32 ) {
16
+ func assertPoolStats (pooler pool.DynamicPooler , hits , misses , timeouts , totals , idles , stales , capacity uint32 ) {
17
17
Expect (pooler .Stats ()).To (Equal (& pool.Stats {
18
18
Hits : hits ,
19
19
Misses : misses ,
20
20
Timeouts : timeouts ,
21
21
TotalConns : totals ,
22
22
IdleConns : idles ,
23
23
StaleConns : stales ,
24
+ QueueCap : capacity ,
24
25
}))
25
26
}
26
27
@@ -63,21 +64,60 @@ var _ = Describe("ConnPool", func() {
63
64
PoolTimeout : time .Hour ,
64
65
IdleTimeout : time .Millisecond ,
65
66
IdleCheckFrequency : time .Millisecond * 500 ,
67
+ ConnReqQueueSize : 1000000 ,
66
68
})
67
69
wg .Wait ()
68
70
69
71
// MinIdleConns should optimistically increase poolSize though actual conn creation is pending
70
- assertPoolStats (connPool , 0 , 0 , 0 , 10 , 10 , 0 )
72
+ assertPoolStats (connPool , 0 , 0 , 0 , 10 , 10 , 0 , 1000000 )
71
73
72
74
// no error since no idle conn queued yet during pool close and stats remains
73
75
Expect (connPool .Close ()).NotTo (HaveOccurred ())
74
- assertPoolStats (connPool , 0 , 0 , 0 , 10 , 10 , 0 )
76
+ assertPoolStats (connPool , 0 , 0 , 0 , 10 , 10 , 0 , 1000000 )
75
77
76
78
close (closedChan ) // release the channel to make all dail success
77
79
78
80
// wait for 5ms and all conn put back idle list should fail and decrease pool size
79
81
time .Sleep (time .Millisecond * 5 )
80
- assertPoolStats (connPool , 0 , 0 , 0 , 0 , 0 , 0 )
82
+ assertPoolStats (connPool , 0 , 0 , 0 , 0 , 0 , 0 , 1000000 )
83
+ })
84
+
85
+ It ("should create idle connections then safe close and queue size is bigger than 100x of pool size" , func () {
86
+ const minIdleConns = 10
87
+
88
+ var (
89
+ wg sync.WaitGroup
90
+ closedChan = make (chan struct {})
91
+ )
92
+ wg .Add (minIdleConns )
93
+ connPool = pool .NewDynamicConnPool (& pool.Options {
94
+ Dialer : func (ctx context.Context ) (net.Conn , error ) {
95
+ wg .Done ()
96
+ <- closedChan
97
+ return & net.TCPConn {}, nil
98
+ },
99
+ PoolSize : 10 ,
100
+ MinIdleConns : minIdleConns ,
101
+ MaxIdleConns : 10 ,
102
+ PoolTimeout : time .Hour ,
103
+ IdleTimeout : time .Millisecond ,
104
+ IdleCheckFrequency : time .Millisecond * 500 ,
105
+ ConnReqQueueSize : 100 ,
106
+ })
107
+ wg .Wait ()
108
+
109
+ // MinIdleConns should optimistically increase poolSize though actual conn creation is pending
110
+ assertPoolStats (connPool , 0 , 0 , 0 , 10 , 10 , 0 , 1000 )
111
+
112
+ // no error since no idle conn queued yet during pool close and stats remains
113
+ Expect (connPool .Close ()).NotTo (HaveOccurred ())
114
+ assertPoolStats (connPool , 0 , 0 , 0 , 10 , 10 , 0 , 1000 )
115
+
116
+ close (closedChan ) // release the channel to make all dail success
117
+
118
+ // wait for 5ms and all conn put back idle list should fail and decrease pool size
119
+ time .Sleep (time .Millisecond * 5 )
120
+ assertPoolStats (connPool , 0 , 0 , 0 , 0 , 0 , 0 , 1000 )
81
121
})
82
122
83
123
It ("should unblock client when conn is removed" , func () {
@@ -642,7 +682,7 @@ var _ = Describe("dynamic update", func() {
642
682
getConnsExpectNoErr (connPool , minIdleConns - 1 ) // use all connections
643
683
644
684
// all get request should hit and use up all idle connections
645
- assertPoolStats (connPool , minIdleConns - 1 , 0 , 0 , minIdleConns - 1 , 0 , 0 )
685
+ assertPoolStats (connPool , minIdleConns - 1 , 0 , 0 , minIdleConns - 1 , 0 , 0 , 1000000 )
646
686
647
687
done := make (chan struct {})
648
688
go func () {
0 commit comments