Skip to content

Commit df99e7f

Browse files
committed
Add aggressive flush before test to prevent event interference
CI shows 72 events instead of 60. Debug output reveals: - Client captured: 60 events (correct) - Server received: 72 events across 2 batches The 12 extra events accumulate in the timing window between fixture cleanup and mock setup. Other tests (like circuit breaker tests not in our xdist_group) may be sending telemetry concurrently. Solution: Add an explicit flush+shutdown RIGHT BEFORE setting up the mock to ensure a completely clean slate with zero buffered events. Signed-off-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent a62073f commit df99e7f

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

tests/e2e/test_concurrent_telemetry.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ def telemetry_setup_teardown(self):
3737
this robust and automatic.
3838
"""
3939
# Clean up BEFORE test starts to ensure no leftover state from previous tests
40+
# Use wait=True to ensure all pending telemetry from previous tests completes
41+
# This prevents those events from being captured by this test's mock
4042
if TelemetryClientFactory._executor:
41-
TelemetryClientFactory._executor.shutdown(wait=True)
43+
TelemetryClientFactory._executor.shutdown(wait=True) # WAIT for pending telemetry
4244
TelemetryClientFactory._executor = None
4345
TelemetryClientFactory._stop_flush_thread()
4446
TelemetryClientFactory._flush_event.clear() # Clear the event flag
@@ -49,8 +51,9 @@ def telemetry_setup_teardown(self):
4951
yield
5052
finally:
5153
# Clean up AFTER test ends
54+
# Use wait=True to ensure this test's telemetry completes before next test starts
5255
if TelemetryClientFactory._executor:
53-
TelemetryClientFactory._executor.shutdown(wait=True)
56+
TelemetryClientFactory._executor.shutdown(wait=True) # WAIT for this test's telemetry
5457
TelemetryClientFactory._executor = None
5558
TelemetryClientFactory._stop_flush_thread()
5659
TelemetryClientFactory._flush_event.clear() # Clear the event flag
@@ -62,6 +65,14 @@ def test_concurrent_queries_sends_telemetry(self):
6265
An E2E test where concurrent threads execute real queries against
6366
the staging endpoint, while we capture and verify the generated telemetry.
6467
"""
68+
# Extra flush right before test starts to clear any events that accumulated
69+
# between fixture cleanup and now (e.g., from other tests on same worker)
70+
if TelemetryClientFactory._executor:
71+
TelemetryClientFactory._executor.shutdown(wait=True)
72+
TelemetryClientFactory._executor = None
73+
TelemetryClientFactory._clients.clear()
74+
TelemetryClientFactory._initialized = False
75+
6576
num_threads = 30
6677
capture_lock = threading.Lock()
6778
captured_telemetry = []

tests/e2e/test_telemetry_e2e.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ class TestTelemetryE2E(TelemetryTestBase):
5252
def telemetry_setup_teardown(self):
5353
"""Clean up telemetry client state before and after each test"""
5454
# Clean up BEFORE test starts
55+
# Use wait=True to ensure all pending telemetry from previous tests completes
5556
if TelemetryClientFactory._executor:
56-
TelemetryClientFactory._executor.shutdown(wait=True)
57+
TelemetryClientFactory._executor.shutdown(wait=True) # WAIT for pending telemetry
5758
TelemetryClientFactory._executor = None
5859
TelemetryClientFactory._stop_flush_thread()
5960
TelemetryClientFactory._flush_event.clear() # Clear the event flag
@@ -72,8 +73,9 @@ def telemetry_setup_teardown(self):
7273
yield
7374
finally:
7475
# Clean up AFTER test ends
76+
# Use wait=True to ensure this test's telemetry completes
7577
if TelemetryClientFactory._executor:
76-
TelemetryClientFactory._executor.shutdown(wait=True)
78+
TelemetryClientFactory._executor.shutdown(wait=True) # WAIT for this test's telemetry
7779
TelemetryClientFactory._executor = None
7880
TelemetryClientFactory._stop_flush_thread()
7981
TelemetryClientFactory._flush_event.clear() # Clear the event flag

0 commit comments

Comments
 (0)