Skip to content

Commit 7a97df8

Browse files
committed
fix: respect timeout_millis in BatchProcessor.force_flush
Fixes #4568.
1 parent 45f8937 commit 7a97df8

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

opentelemetry-sdk/tests/shared_internal/test_batch_processor.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,26 +199,26 @@ def test_force_flush_returns_false_when_timeout_exceeded(
199199
def slow_export(batch):
200200
nonlocal call_count
201201
call_count += 1
202-
# Sleep long enough that the deadline is exceeded after first batch.
203-
time.sleep(0.2)
202+
# Sleep longer than the force_flush timeout.
203+
time.sleep(0.5)
204204

205205
exporter = Mock()
206206
exporter.export.side_effect = slow_export
207207
batch_processor = batch_processor_class(
208208
exporter,
209209
max_queue_size=200,
210-
max_export_batch_size=1,
210+
max_export_batch_size=200,
211211
# Long enough that the worker thread won't wake up during the test.
212212
schedule_delay_millis=30000,
213213
export_timeout_millis=500,
214214
)
215-
for _ in range(50):
215+
for _ in range(10):
216216
batch_processor._batch_processor.emit(telemetry)
217-
# 100ms timeout, each export takes 200ms, so deadline is hit after first batch.
217+
# force_flush acquires lock immediately since worker is sleeping for 30s.
218+
# First export takes 500ms, deadline of 100ms fires before second batch.
218219
result = batch_processor.force_flush(timeout_millis=100)
219220
assert result is False
220-
# Exporter was called at least once but not for all batches.
221-
assert 1 <= call_count < 50
221+
assert call_count == 1
222222
batch_processor.shutdown()
223223

224224
# pylint: disable=no-self-use

0 commit comments

Comments
 (0)