Skip to content

Commit 1464737

Browse files
committed
fix: respect timeout_millis in BatchProcessor.force_flush
Fixes open-telemetry#4568.
1 parent 45f8937 commit 1464737

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

opentelemetry-sdk/tests/shared_internal/test_batch_processor.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff 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.

0 commit comments

Comments
 (0)