@@ -894,6 +894,11 @@ func (s *WsControllerSuite) TestControllerShutdown() {
894894}
895895
896896func (s * WsControllerSuite ) TestKeepaliveRoutine () {
897+ keepaliveConfig := KeepaliveConfig {
898+ PingPeriod : time .Microsecond ,
899+ PongWait : 2 * time .Microsecond ,
900+ }
901+
897902 s .T ().Run ("Successfully pings connection n times" , func (t * testing.T ) {
898903 conn := connmock .NewWebsocketConnection (t )
899904 conn .On ("Close" ).Return (nil ).Once ()
@@ -923,9 +928,9 @@ func (s *WsControllerSuite) TestKeepaliveRoutine() {
923928
924929 factory := dpmock .NewDataProviderFactory (t )
925930 controller := NewWebSocketController (s .logger , s .wsConfig , conn , factory )
926- controller .HandleConnection ( context . Background ())
931+ controller .keepaliveConfig = keepaliveConfig
927932
928- conn . AssertExpectations ( t )
933+ controller . HandleConnection ( context . Background () )
929934 })
930935
931936 s .T ().Run ("Error on write to closed connection" , func (t * testing.T ) {
@@ -938,15 +943,14 @@ func (s *WsControllerSuite) TestKeepaliveRoutine() {
938943
939944 factory := dpmock .NewDataProviderFactory (t )
940945 controller := NewWebSocketController (s .logger , s .wsConfig , conn , factory )
946+ controller .keepaliveConfig = keepaliveConfig
941947
942948 ctx , cancel := context .WithCancel (context .Background ())
943949 defer cancel ()
944950
945951 err := controller .keepalive (ctx )
946952 s .Require ().Error (err )
947953 s .Require ().ErrorIs (expectedError , err )
948-
949- conn .AssertExpectations (t )
950954 })
951955
952956 s .T ().Run ("Error on write to open connection" , func (t * testing.T ) {
@@ -958,30 +962,28 @@ func (s *WsControllerSuite) TestKeepaliveRoutine() {
958962
959963 factory := dpmock .NewDataProviderFactory (t )
960964 controller := NewWebSocketController (s .logger , s .wsConfig , conn , factory )
965+ controller .keepaliveConfig = keepaliveConfig
961966
962967 ctx , cancel := context .WithCancel (context .Background ())
963968 defer cancel ()
964969
965970 err := controller .keepalive (ctx )
966971 s .Require ().Error (err )
967972 s .Require ().ErrorContains (err , "error sending ping" )
968-
969- conn .AssertExpectations (t )
970973 })
971974
972975 s .T ().Run ("Context cancelled" , func (t * testing.T ) {
973976 conn := connmock .NewWebsocketConnection (t )
974977 factory := dpmock .NewDataProviderFactory (t )
975978 controller := NewWebSocketController (s .logger , s .wsConfig , conn , factory )
979+ controller .keepaliveConfig = keepaliveConfig
976980
977981 ctx , cancel := context .WithCancel (context .Background ())
978982 cancel () // Immediately cancel the context
979983
980984 // Start the keepalive process with the context canceled
981985 err := controller .keepalive (ctx )
982986 s .Require ().NoError (err )
983-
984- conn .AssertExpectations (t ) // Should not invoke WriteMessage after context cancellation
985987 })
986988}
987989
0 commit comments