test: Fix flaky event manager tests by replacing sleep with wait#1830
Merged
Conversation
…stic wait Replace `asyncio.sleep(0.1)` with `event_manager.wait_for_all_listeners_to_complete()` in event manager tests. The sleep-based approach was a race condition — under CI load, 100ms wasn't always enough for `asyncio.to_thread()` to complete. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1830 +/- ##
==========================================
- Coverage 92.29% 92.27% -0.02%
==========================================
Files 157 157
Lines 10900 10900
==========================================
- Hits 10060 10058 -2
- Misses 840 842 +2
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:
|
Pijukatel
approved these changes
Apr 2, 2026
vdusek
added a commit
that referenced
this pull request
May 9, 2026
) ## Summary The `test_emit_system_info_event` test was flaking on macOS CI (e.g. [run 25595850020](https://github.com/apify/crawlee-python/actions/runs/25595850020/job/75141531498)). It registered a listener and slept for `50ms × 10 = 500ms` hoping at least one `SYSTEM_INFO` event would fire. Under heavy parallel xdist load, `psutil.cpu_percent(interval=0.1)` running inside `asyncio.to_thread` could be delayed enough that no event reached the listener within the 500ms window. This replaces the fixed sleep with an `asyncio.Event` that the listener sets, awaited via `asyncio.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 in `test_event_manager.py`.
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
asyncio.sleep(0.1)withevent_manager.wait_for_all_listeners_to_complete()in 5 event manager testsasyncio.to_thread()to complete sync listeners🤖 Generated with Claude Code