1
1
package pool_test
2
2
3
3
import (
4
+ "context"
4
5
"sync"
5
6
"testing"
6
7
"time"
@@ -12,6 +13,7 @@ import (
12
13
)
13
14
14
15
var _ = Describe ("ConnPool" , func () {
16
+ c := context .Background ()
15
17
var connPool * pool.ConnPool
16
18
17
19
BeforeEach (func () {
@@ -30,13 +32,13 @@ var _ = Describe("ConnPool", func() {
30
32
31
33
It ("should unblock client when conn is removed" , func () {
32
34
// Reserve one connection.
33
- cn , err := connPool .Get (nil )
35
+ cn , err := connPool .Get (c )
34
36
Expect (err ).NotTo (HaveOccurred ())
35
37
36
38
// Reserve all other connections.
37
39
var cns []* pool.Conn
38
40
for i := 0 ; i < 9 ; i ++ {
39
- cn , err := connPool .Get (nil )
41
+ cn , err := connPool .Get (c )
40
42
Expect (err ).NotTo (HaveOccurred ())
41
43
cns = append (cns , cn )
42
44
}
@@ -47,7 +49,7 @@ var _ = Describe("ConnPool", func() {
47
49
defer GinkgoRecover ()
48
50
49
51
started <- true
50
- _ , err := connPool .Get (nil )
52
+ _ , err := connPool .Get (c )
51
53
Expect (err ).NotTo (HaveOccurred ())
52
54
done <- true
53
55
@@ -80,6 +82,7 @@ var _ = Describe("ConnPool", func() {
80
82
})
81
83
82
84
var _ = Describe ("MinIdleConns" , func () {
85
+ c := context .Background ()
83
86
const poolSize = 100
84
87
var minIdleConns int
85
88
var connPool * pool.ConnPool
@@ -110,7 +113,7 @@ var _ = Describe("MinIdleConns", func() {
110
113
111
114
BeforeEach (func () {
112
115
var err error
113
- cn , err = connPool .Get (nil )
116
+ cn , err = connPool .Get (c )
114
117
Expect (err ).NotTo (HaveOccurred ())
115
118
116
119
Eventually (func () int {
@@ -145,7 +148,7 @@ var _ = Describe("MinIdleConns", func() {
145
148
perform (poolSize , func (_ int ) {
146
149
defer GinkgoRecover ()
147
150
148
- cn , err := connPool .Get (nil )
151
+ cn , err := connPool .Get (c )
149
152
Expect (err ).NotTo (HaveOccurred ())
150
153
mu .Lock ()
151
154
cns = append (cns , cn )
@@ -160,7 +163,7 @@ var _ = Describe("MinIdleConns", func() {
160
163
It ("Get is blocked" , func () {
161
164
done := make (chan struct {})
162
165
go func () {
163
- connPool .Get (nil )
166
+ connPool .Get (c )
164
167
close (done )
165
168
}()
166
169
@@ -247,6 +250,8 @@ var _ = Describe("MinIdleConns", func() {
247
250
})
248
251
249
252
var _ = Describe ("conns reaper" , func () {
253
+ c := context .Background ()
254
+
250
255
const idleTimeout = time .Minute
251
256
const maxAge = time .Hour
252
257
@@ -274,7 +279,7 @@ var _ = Describe("conns reaper", func() {
274
279
// add stale connections
275
280
staleConns = nil
276
281
for i := 0 ; i < 3 ; i ++ {
277
- cn , err := connPool .Get (nil )
282
+ cn , err := connPool .Get (c )
278
283
Expect (err ).NotTo (HaveOccurred ())
279
284
switch typ {
280
285
case "idle" :
@@ -288,7 +293,7 @@ var _ = Describe("conns reaper", func() {
288
293
289
294
// add fresh connections
290
295
for i := 0 ; i < 3 ; i ++ {
291
- cn , err := connPool .Get (nil )
296
+ cn , err := connPool .Get (c )
292
297
Expect (err ).NotTo (HaveOccurred ())
293
298
conns = append (conns , cn )
294
299
}
@@ -333,7 +338,7 @@ var _ = Describe("conns reaper", func() {
333
338
for j := 0 ; j < 3 ; j ++ {
334
339
var freeCns []* pool.Conn
335
340
for i := 0 ; i < 3 ; i ++ {
336
- cn , err := connPool .Get (nil )
341
+ cn , err := connPool .Get (c )
337
342
Expect (err ).NotTo (HaveOccurred ())
338
343
Expect (cn ).NotTo (BeNil ())
339
344
freeCns = append (freeCns , cn )
@@ -342,7 +347,7 @@ var _ = Describe("conns reaper", func() {
342
347
Expect (connPool .Len ()).To (Equal (3 ))
343
348
Expect (connPool .IdleLen ()).To (Equal (0 ))
344
349
345
- cn , err := connPool .Get (nil )
350
+ cn , err := connPool .Get (c )
346
351
Expect (err ).NotTo (HaveOccurred ())
347
352
Expect (cn ).NotTo (BeNil ())
348
353
conns = append (conns , cn )
@@ -370,6 +375,7 @@ var _ = Describe("conns reaper", func() {
370
375
})
371
376
372
377
var _ = Describe ("race" , func () {
378
+ c := context .Background ()
373
379
var connPool * pool.ConnPool
374
380
var C , N int
375
381
@@ -396,15 +402,15 @@ var _ = Describe("race", func() {
396
402
397
403
perform (C , func (id int ) {
398
404
for i := 0 ; i < N ; i ++ {
399
- cn , err := connPool .Get (nil )
405
+ cn , err := connPool .Get (c )
400
406
Expect (err ).NotTo (HaveOccurred ())
401
407
if err == nil {
402
408
connPool .Put (cn )
403
409
}
404
410
}
405
411
}, func (id int ) {
406
412
for i := 0 ; i < N ; i ++ {
407
- cn , err := connPool .Get (nil )
413
+ cn , err := connPool .Get (c )
408
414
Expect (err ).NotTo (HaveOccurred ())
409
415
if err == nil {
410
416
connPool .Remove (cn )
0 commit comments