File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -684,6 +684,7 @@ def _thread_main(self, ready):
684684 exc ,
685685 )
686686
687+ self .stop ()
687688 _LOGGER .info ("%s exiting" , _BIDIRECTIONAL_CONSUMER_NAME )
688689
689690 def start (self ):
Original file line number Diff line number Diff line change @@ -918,3 +918,23 @@ def test_stop_error_logs(self, caplog):
918918 error_logs = [r .message for r in caplog .records if r .levelname == "ERROR" ]
919919 assert not error_logs , f"Found unexpected ERROR logs: { error_logs } "
920920 bidi_rpc .is_active = False
921+
922+ def test_fatal_exceptions_will_shutdown_consumer (self , caplog ):
923+ """
924+ https://github.com/googleapis/python-api-core/issues/820
925+ Exceptions thrown in the BackgroundConsumer that
926+ lead to the consumer halting should also stop the thread and rpc.
927+ """
928+ caplog .set_level (logging .DEBUG )
929+ bidi_rpc = mock .create_autospec (bidi .BidiRpc , instance = True )
930+ bidi_rpc .is_active = True
931+ on_response = mock .Mock (spec = ["__call__" ])
932+
933+ bidi_rpc .open .side_effect = ValueError ()
934+
935+ consumer = bidi .BackgroundConsumer (bidi_rpc , on_response )
936+
937+ consumer .start ()
938+
939+ # We want to make sure that close is called, which will surface the error to the caller.
940+ bidi_rpc .close .assert_called_once ()
You can’t perform that action at this time.
0 commit comments