test: Fix flaky test_emit_system_info_event by waiting on event#1887
Merged
test: Fix flaky test_emit_system_info_event by waiting on event#1887
test_emit_system_info_event by waiting on event#1887Conversation
Replace the fixed `asyncio.sleep` with an `asyncio.Event` set from the listener and awaited with a generous timeout. Under loaded CI runners, `psutil.cpu_percent(interval=0.1)` running in `asyncio.to_thread` could delay the first emission past the 500ms window, leaving the listener uncalled.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1887 +/- ##
==========================================
- Coverage 92.78% 92.72% -0.07%
==========================================
Files 161 161
Lines 11356 11356
==========================================
- Hits 10537 10530 -7
- Misses 819 826 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
test_emit_system_info_eventtest was flaking on macOS CI (e.g. run 25595850020). It registered a listener and slept for50ms × 10 = 500mshoping at least oneSYSTEM_INFOevent would fire. Under heavy parallel xdist load,psutil.cpu_percent(interval=0.1)running insideasyncio.to_threadcould be delayed enough that no event reached the listener within the 500ms window.This replaces the fixed sleep with an
asyncio.Eventthat the listener sets, awaited viaasyncio.wait_for(..., timeout=10). The test now returns as soon as the first event is observed and only waits up to 10s as a safety net — same pattern as #1830 for the sibling tests intest_event_manager.py.