1414
1515# pylint: disable=protected-access
1616import gc
17+ import logging
1718import multiprocessing
1819import os
1920import time
@@ -219,27 +220,9 @@ def test_record_processor_is_garbage_collected(
219220 # Then the reference to the processor should no longer exist
220221 assert weak_ref () is None
221222
222- def test_shutdown_cancels_longrunning_export (self , batch_processor_class , telemetry , caplog ):
223- # This exporter throws an exception if it's export sleep cannot finish.
224- exporter = MockExporterForTesting (export_sleep = 3 )
225- processor = batch_processor_class (
226- exporter ,
227- max_queue_size = 200 ,
228- max_export_batch_size = 10 ,
229- schedule_delay_millis = 30000 ,
230- )
231- processor ._batch_processor .emit (telemetry )
232- before = time .time ()
233- # Shutdown should cancel export after 2 seconds
234- processor ._batch_processor .shutdown (timeout_millis = 2000 )
235- after = time .time ()
236- assert after - before < 2.2
237- assert "Exception while exporting" in caplog .text
238-
239223
240224 def test_shutdown_allows_1_export_to_finish (self , batch_processor_class , telemetry , caplog ):
241225 # This exporter throws an exception if it's export sleep cannot finish.
242- dir (caplog )
243226 exporter = MockExporterForTesting (export_sleep = 2 )
244227 processor = batch_processor_class (
245228 exporter ,
@@ -253,8 +236,14 @@ def test_shutdown_allows_1_export_to_finish(self, batch_processor_class, telemet
253236 processor ._batch_processor .emit (telemetry )
254237 before = time .time ()
255238 processor ._batch_processor .shutdown (timeout_millis = 3000 )
239+ # Shutdown does not kill the thread.
240+ assert processor ._batch_processor ._worker_thread .is_alive () is True
241+
256242 after = time .time ()
257243 assert after - before < 3.2
244+ # Thread will naturally finish after a little bit.
245+ time .sleep (.1 )
246+ assert processor ._batch_processor ._worker_thread .is_alive () is False
258247 # Expect the second call to be interrupted by shutdown, and the third call to never be made.
259248 assert "Exception while exporting" in caplog .text
260249 assert 2 == exporter .num_export_calls
0 commit comments