File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -387,4 +387,33 @@ var _ = Describe("race", func() {
387
387
Expect (stats .WaitCount ).To (Equal (uint32 (1 )))
388
388
Expect (stats .WaitDurationNs ).To (BeNumerically ("~" , time .Second .Nanoseconds (), 100 * time .Millisecond .Nanoseconds ()))
389
389
})
390
+
391
+ It ("timeout" , func () {
392
+ testPoolTimeout := 1 * time .Second
393
+ opt := & pool.Options {
394
+ Dialer : func (ctx context.Context ) (net.Conn , error ) {
395
+ // Artificial delay to force pool timeout
396
+ time .Sleep (3 * testPoolTimeout )
397
+
398
+ return & net.TCPConn {}, nil
399
+ },
400
+ PoolSize : 1 ,
401
+ PoolTimeout : testPoolTimeout ,
402
+ }
403
+ p := pool .NewConnPool (opt )
404
+
405
+ stats := p .Stats ()
406
+ Expect (stats .Timeouts ).To (Equal (uint32 (0 )))
407
+
408
+ conn , err := p .Get (ctx )
409
+ Expect (err ).NotTo (HaveOccurred ())
410
+ _ , err = p .Get (ctx )
411
+ Expect (err ).To (MatchError (pool .ErrPoolTimeout ))
412
+ p .Put (ctx , conn )
413
+ conn , err = p .Get (ctx )
414
+ Expect (err ).NotTo (HaveOccurred ())
415
+
416
+ stats = p .Stats ()
417
+ Expect (stats .Timeouts ).To (Equal (uint32 (1 )))
418
+ })
390
419
})
You can’t perform that action at this time.
0 commit comments