@@ -817,79 +817,6 @@ func TestPool(t *testing.T) {
817817 assert .Containsf (t , err .Error (), "canceled" , `expected error message to contain "canceled"` )
818818 }
819819
820- p .close (context .Background ())
821- })
822- t .Run ("discards connections closed by the server side" , func (t * testing.T ) {
823- t .Parallel ()
824-
825- cleanup := make (chan struct {})
826- defer close (cleanup )
827-
828- ncs := make (chan net.Conn , 2 )
829- addr := bootstrapConnections (t , 2 , func (nc net.Conn ) {
830- // Send all "server-side" connections to a channel so we can
831- // interact with them during the test.
832- ncs <- nc
833-
834- <- cleanup
835- _ = nc .Close ()
836- })
837-
838- d := newdialer (& net.Dialer {})
839- p := newPool (poolConfig {
840- Address : address .Address (addr .String ()),
841- }, WithDialer (func (Dialer ) Dialer { return d }))
842- err := p .ready ()
843- require .NoError (t , err )
844-
845- // Add 1 idle connection to the pool by checking-out and checking-in
846- // a connection.
847- conn , err := p .checkOut (context .Background ())
848- require .NoError (t , err )
849- err = p .checkIn (conn )
850- require .NoError (t , err )
851- assertConnectionsOpened (t , d , 1 )
852- assert .Equalf (t , 1 , p .availableConnectionCount (), "should be 1 idle connections in pool" )
853- assert .Equalf (t , 1 , p .totalConnectionCount (), "should be 1 total connection in pool" )
854-
855- // Make that connection appear as if it's been idle for a minute.
856- conn .idleStart .Store (time .Now ().Add (- 1 * time .Minute ))
857-
858- // Close the "server-side" of the connection we just created. The idle
859- // connection in the pool is now unusable because the "server-side"
860- // closed it.
861- nc := <- ncs
862- err = nc .Close ()
863- require .NoError (t , err )
864-
865- // In a separate goroutine, write a valid wire message to the 2nd
866- // connection that's about to be created. Stop waiting for a 2nd
867- // connection after 100ms to prevent leaking a goroutine.
868- go func () {
869- select {
870- case nc := <- ncs :
871- _ , err := nc .Write ([]byte {5 , 0 , 0 , 0 , 0 })
872- require .NoError (t , err , "Write error" )
873- case <- time .After (100 * time .Millisecond ):
874- }
875- }()
876-
877- // Check out a connection and try to read from it. Expect the pool to
878- // discard the connection that was closed by the "server-side" and
879- // return a newly created connection instead.
880- conn , err = p .checkOut (context .Background ())
881- require .NoError (t , err )
882- msg , err := conn .readWireMessage (context .Background ())
883- require .NoError (t , err )
884- assert .Equal (t , []byte {5 , 0 , 0 , 0 , 0 }, msg )
885-
886- err = p .checkIn (conn )
887- require .NoError (t , err )
888-
889- assertConnectionsOpened (t , d , 2 )
890- assert .Equalf (t , 1 , p .availableConnectionCount (), "should be 1 idle connections in pool" )
891- assert .Equalf (t , 1 , p .totalConnectionCount (), "should be 1 total connection in pool" )
892-
893820 p .close (context .Background ())
894821 })
895822 })
0 commit comments