File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -664,7 +664,8 @@ def _thread_main(self, ready):
664
664
_LOGGER .debug ("waiting for recv." )
665
665
response = self ._bidi_rpc .recv ()
666
666
_LOGGER .debug ("recved response." )
667
- self ._on_response (response )
667
+ if self ._on_response is not None :
668
+ self ._on_response (response )
668
669
669
670
except exceptions .GoogleAPICallError as exc :
670
671
_LOGGER .debug (
Original file line number Diff line number Diff line change 16
16
import logging
17
17
import queue
18
18
import threading
19
+ import time
19
20
20
21
try :
21
22
from unittest import mock
@@ -894,3 +895,26 @@ def close_side_effect():
894
895
895
896
# calling stop twice should not result in an error.
896
897
consumer .stop ()
898
+
899
+ def test_stop_error_logs (self , caplog ):
900
+ """
901
+ Closing the client should result in no internal error logs
902
+
903
+ https://github.com/googleapis/python-api-core/issues/788
904
+ """
905
+ caplog .set_level (logging .DEBUG )
906
+ bidi_rpc = mock .create_autospec (bidi .BidiRpc , instance = True )
907
+ bidi_rpc .is_active = True
908
+ on_response = mock .Mock (spec = ["__call__" ])
909
+
910
+ consumer = bidi .BackgroundConsumer (bidi_rpc , on_response )
911
+
912
+ consumer .start ()
913
+ consumer .stop ()
914
+ # let the background thread run for a while before exiting
915
+ time .sleep (0.1 )
916
+ bidi_rpc .is_active = False
917
+ # running thread should not result in error logs
918
+ error_logs = [r .message for r in caplog .records if r .levelname == "ERROR" ]
919
+ assert not error_logs , f"Found unexpected ERROR logs: { error_logs } "
920
+ bidi_rpc .is_active = False
You can’t perform that action at this time.
0 commit comments