File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed
Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -97,6 +97,9 @@ def _ws_io(self):
9797 # noinspection PyBroadException
9898 try :
9999 yield
100+ except websocket .WebSocketConnectionClosedException as e :
101+ self .exception = e
102+ logging .warning ("WS messaging thread terminated due to closed connection" )
100103 except Exception as e :
101104 self .exception = e
102105 logging .warning ("WS messaging thread terminated with exception" , exc_info = True )
Original file line number Diff line number Diff line change @@ -595,3 +595,32 @@ def test_exceeded_max_failures(self):
595595
596596 self .assertEqual (100 , self .session_manager ._last_not_ok )
597597 self .assertEqual (4 , self .session_manager ._message_producer_not_ok_count )
598+
599+
600+ @patch (MODULE_PATH + "logging" )
601+ class Test_WSMessageProducer_ws_io (WSMessageProducerTest ):
602+
603+ def test_WebSocketConnectionClosedException (self , _logging ):
604+ self .ws_message_producer .close = MagicMock ()
605+
606+ with self .ws_message_producer ._ws_io ():
607+ raise WebSocketConnectionClosedException ("foo" )
608+
609+ _logging .warning .assert_called_once_with (
610+ "WS messaging thread terminated due to closed connection"
611+ )
612+ self .ws_message_producer .close .assert_called_once_with ()
613+
614+ def test_other_exception (self , _logging ):
615+ self .ws_message_producer .close = MagicMock ()
616+
617+ e = Exception ("foo" )
618+
619+ with self .ws_message_producer ._ws_io ():
620+ raise e
621+
622+ _logging .warning .assert_called_once_with (
623+ "WS messaging thread terminated with exception" , exc_info = True
624+ )
625+ self .ws_message_producer .close .assert_called_once_with ()
626+ self .assertEqual (e , self .ws_message_producer .exception )
You can’t perform that action at this time.
0 commit comments