File tree Expand file tree Collapse file tree
opentelemetry-sdk/tests/shared_internal Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -194,13 +194,15 @@ def test_force_flush_returns_true_when_all_exported(
194194 def test_force_flush_returns_false_when_timeout_exceeded (
195195 self , batch_processor_class , telemetry
196196 ):
197+ export_started = threading .Event ()
197198 call_count = 0
198199
199200 def slow_export (batch ):
200201 nonlocal call_count
201202 call_count += 1
202- # Sleep long enough that the deadline is exceeded after first batch.
203- time .sleep (0.2 )
203+ # Signal that export has started, then sleep long enough for deadline to be exceeded.
204+ export_started .set ()
205+ time .sleep (0.5 )
204206
205207 exporter = Mock ()
206208 exporter .export .side_effect = slow_export
@@ -214,7 +216,9 @@ def slow_export(batch):
214216 )
215217 for _ in range (50 ):
216218 batch_processor ._batch_processor .emit (telemetry )
217- # 100ms timeout, each export takes 200ms, so deadline is hit after first batch.
219+ # Wait until the worker has started its first export before calling force_flush.
220+ export_started .wait ()
221+ # Timeout is 100ms, each export takes 500ms, so deadline is hit before second batch.
218222 result = batch_processor .force_flush (timeout_millis = 100 )
219223 assert result is False
220224 # Exporter was called at least once but not for all batches.
You can’t perform that action at this time.
0 commit comments