@@ -645,6 +645,7 @@ func TestPool(t *testing.T) {
645
645
assert .IsTypef (t , WaitQueueTimeoutError {}, err , "expected a WaitQueueTimeoutError" )
646
646
if err , ok := err .(WaitQueueTimeoutError ); ok {
647
647
assert .Equalf (t , context .DeadlineExceeded , err .Unwrap (), "expected wrapped error to be a context.Timeout" )
648
+ assert .Containsf (t , err .Error (), "timed out" , `expected error message to contain "timed out"` )
648
649
}
649
650
650
651
p .close (context .Background ())
@@ -773,6 +774,42 @@ func TestPool(t *testing.T) {
773
774
assert .Equalf (t , 2 , p .totalConnectionCount (), "pool should have 2 total connection" )
774
775
assert .Equalf (t , 0 , p .availableConnectionCount (), "pool should have 0 idle connection" )
775
776
777
+ p .close (context .Background ())
778
+ })
779
+ t .Run ("canceled context in wait queue" , func (t * testing.T ) {
780
+ t .Parallel ()
781
+
782
+ cleanup := make (chan struct {})
783
+ defer close (cleanup )
784
+ addr := bootstrapConnections (t , 1 , func (nc net.Conn ) {
785
+ <- cleanup
786
+ _ = nc .Close ()
787
+ })
788
+
789
+ p := newPool (poolConfig {
790
+ Address : address .Address (addr .String ()),
791
+ MaxPoolSize : 1 ,
792
+ })
793
+ err := p .ready ()
794
+ noerr (t , err )
795
+
796
+ // Check out first connection.
797
+ _ , err = p .checkOut (context .Background ())
798
+ noerr (t , err )
799
+
800
+ // Use a canceled context to check out another connection.
801
+ cancelCtx , cancel := context .WithCancel (context .Background ())
802
+ cancel ()
803
+ _ , err = p .checkOut (cancelCtx )
804
+ assert .NotNilf (t , err , "expected a non-nil error" )
805
+
806
+ // Assert that error received is WaitQueueTimeoutError with context canceled.
807
+ assert .IsTypef (t , WaitQueueTimeoutError {}, err , "expected a WaitQueueTimeoutError" )
808
+ if err , ok := err .(WaitQueueTimeoutError ); ok {
809
+ assert .Equalf (t , context .Canceled , err .Unwrap (), "expected wrapped error to be a context.Canceled" )
810
+ assert .Containsf (t , err .Error (), "canceled" , `expected error message to contain "canceled"` )
811
+ }
812
+
776
813
p .close (context .Background ())
777
814
})
778
815
})
0 commit comments