@@ -843,79 +843,6 @@ func TestPool_checkOut(t *testing.T) {
843843 assert .Containsf (t , err .Error (), "canceled" , `expected error message to contain "canceled"` )
844844 }
845845
846- p .close (context .Background ())
847- })
848- t .Run ("discards connections closed by the server side" , func (t * testing.T ) {
849- t .Parallel ()
850-
851- cleanup := make (chan struct {})
852- defer close (cleanup )
853-
854- ncs := make (chan net.Conn , 2 )
855- addr := bootstrapConnections (t , 2 , func (nc net.Conn ) {
856- // Send all "server-side" connections to a channel so we can
857- // interact with them during the test.
858- ncs <- nc
859-
860- <- cleanup
861- _ = nc .Close ()
862- })
863-
864- d := newdialer (& net.Dialer {})
865- p := newPool (poolConfig {
866- Address : address .Address (addr .String ()),
867- }, WithDialer (func (Dialer ) Dialer { return d }))
868- err := p .ready ()
869- require .NoError (t , err )
870-
871- // Add 1 idle connection to the pool by checking-out and checking-in
872- // a connection.
873- conn , err := p .checkOut (context .Background ())
874- require .NoError (t , err )
875- err = p .checkIn (conn )
876- require .NoError (t , err )
877- assertConnectionsOpened (t , d , 1 )
878- assert .Equalf (t , 1 , p .availableConnectionCount (), "should be 1 idle connections in pool" )
879- assert .Equalf (t , 1 , p .totalConnectionCount (), "should be 1 total connection in pool" )
880-
881- // Make that connection appear as if it's been idle for a minute.
882- conn .idleStart .Store (time .Now ().Add (- 1 * time .Minute ))
883-
884- // Close the "server-side" of the connection we just created. The idle
885- // connection in the pool is now unusable because the "server-side"
886- // closed it.
887- nc := <- ncs
888- err = nc .Close ()
889- require .NoError (t , err )
890-
891- // In a separate goroutine, write a valid wire message to the 2nd
892- // connection that's about to be created. Stop waiting for a 2nd
893- // connection after 100ms to prevent leaking a goroutine.
894- go func () {
895- select {
896- case nc := <- ncs :
897- _ , err := nc .Write ([]byte {5 , 0 , 0 , 0 , 0 })
898- require .NoError (t , err , "Write error" )
899- case <- time .After (100 * time .Millisecond ):
900- }
901- }()
902-
903- // Check out a connection and try to read from it. Expect the pool to
904- // discard the connection that was closed by the "server-side" and
905- // return a newly created connection instead.
906- conn , err = p .checkOut (context .Background ())
907- require .NoError (t , err )
908- msg , err := conn .readWireMessage (context .Background ())
909- require .NoError (t , err )
910- assert .Equal (t , []byte {5 , 0 , 0 , 0 , 0 }, msg )
911-
912- err = p .checkIn (conn )
913- require .NoError (t , err )
914-
915- assertConnectionsOpened (t , d , 2 )
916- assert .Equalf (t , 1 , p .availableConnectionCount (), "should be 1 idle connections in pool" )
917- assert .Equalf (t , 1 , p .totalConnectionCount (), "should be 1 total connection in pool" )
918-
919846 p .close (context .Background ())
920847 })
921848}
0 commit comments