11# coding: utf-8
22from __future__ import print_function , unicode_literals
33import mock
4+ import sys
45import time
56import threading
67import unittest
@@ -120,8 +121,7 @@ def sleep(time):
120121 self .assertEqual (self .uploader_calls , len (RETRY_SCHEDULE ) + 1 )
121122 self .assertEqual (self .sleep_calls , len (RETRY_SCHEDULE ))
122123
123- @mock .patch ('logtail.flusher.sys.exit' )
124- def test_shutdown_condition_empties_queue_and_calls_exit (self , mock_exit ):
124+ def test_shutdown_condition_empties_queue_and_shuts_down (self ):
125125 self .buffer_capacity = 10
126126 num_items = 5
127127 first_frame = list (range (self .buffer_capacity ))
@@ -141,4 +141,19 @@ def uploader(frame):
141141
142142 fw .step ()
143143 self .assertEqual (self .upload_calls , 1 )
144- self .assertEqual (mock_exit .call_count , 1 )
144+ self .assertFalse (fw .should_run )
145+
146+ # test relies on overriding excepthook which is available from 3.8+
147+ @unittest .skipIf (sys .version_info < (3 , 8 ), "Test skipped because overriding excepthook is only available on Python 3.8+" )
148+ def test_shutdown_dont_raise_exception_in_thread (self ):
149+ original_excepthook = threading .excepthook
150+ threading .excepthook = mock .Mock ()
151+
152+ _ , _ , fw = self ._setup_worker ()
153+ fw .parent_thread = mock .MagicMock (is_alive = lambda : False )
154+ fw .step ()
155+
156+ self .assertFalse (fw .should_run )
157+ self .assertFalse (threading .excepthook .called )
158+
159+ threading .excepthook = original_excepthook
0 commit comments