1
1
# coding: utf-8
2
2
from __future__ import print_function , unicode_literals
3
3
import mock
4
+ import sys
4
5
import time
5
6
import threading
6
7
import unittest
@@ -120,8 +121,7 @@ def sleep(time):
120
121
self .assertEqual (self .uploader_calls , len (RETRY_SCHEDULE ) + 1 )
121
122
self .assertEqual (self .sleep_calls , len (RETRY_SCHEDULE ))
122
123
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 ):
125
125
self .buffer_capacity = 10
126
126
num_items = 5
127
127
first_frame = list (range (self .buffer_capacity ))
@@ -141,4 +141,19 @@ def uploader(frame):
141
141
142
142
fw .step ()
143
143
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