test: fix flaky test_run_coro_with_timeout#1683
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1683 +/- ##
=======================================
Coverage 99.76% 99.76%
=======================================
Files 33 33
Lines 3401 3401
Branches 461 461
=======================================
Hits 3393 3393
Misses 5 5
Partials 3 3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR aims to make test_run_coro_with_timeout less flaky on slow CI runners by giving the event loop more time to schedule the coroutine before asserting on the created task.
Changes:
- Adds a synchronization event to detect when the inner task is created.
- Increases the coroutine timeout and inner sleep duration to reduce scheduling sensitivity.
- Removes a redundant assertion inside the coroutine.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
PR Review — test: fix flaky test_run_coro_with_timeoutThe timeout bump (0.1 → 50 ms outer, 0.2s → 1s inner) is the right move and is what's actually making the test reliable — 50ms of headroom is plenty for the loop to schedule the inner coroutine before 🟡 Important1. `threading.Event.wait()` blocks the loop that needs to set the event (`tests/utils/test_asyncio.py`, L143)This test is
What is actually keeping this test green in the 50/50 rerun is the timeout bump from If you want the synchronization to be load-bearing, use Otherwise, this is just a timeout bump dressed up as a race fix — fine, but the comment block and Checklist
SummaryThe timeout bump (0.1 → 50 ms outer, 0.2s → 1s inner) is the right move and is what's actually making the test reliable — 50ms of headroom is plenty for the loop to schedule the inner coroutine before Automated review by Kōan79311dd |
Rebase with requested adjustmentsBranch Changes applied
StatsActions performed
CI statusCI will be checked asynchronously. Automated by Kōan |
What
Make
tests/utils/test_asyncio.py::test_run_coro_with_timeoutreliable on slow / loaded CI runners.Why
Closes #1663. The test patched
_LOADED_SYSTEM_TIMEOUTto0.0and passedtimeout=0.1ms torun_coro_with_timeout, soconcurrent.futures.Future.result()waited just0.0001seconds. On a loaded system the executor thread's.result()could time out before the event loop got a chance to start the scheduled coroutine, leaving thetasknonlocal stillNoneand trippingassert task is not None. Nixpkgs hit this intermittently on the 3.14 build.How
run_coro_with_timeoutto50ms — still well under the innersleep(1), soEventLoopBlockedis still guaranteed, but the loop now has plenty of headroom to schedule the coroutine.asyncio.sleepfrom0.2s to1s for the same headroom reason.threading.Event(task_created) the coroutine sets right after creating the inner task. Afterpytest.raises(EventLoopBlocked)catches, wait up to 1 s on it before asserting ontask. This is the actual race fix; the timeout bump is belt-and-braces.assert task is not None.Testing
poetry run pytest tests/utils/test_asyncio.py::test_run_coro_with_timeout --count=50 --no-cov→ 50/50 pass.poetry run pytest tests/utils/test_asyncio.py --no-cov→ all 7 tests pass.poetry run ruff check tests/utils/test_asyncio.pyandruff format --checkclean.Quality Report
Changes: 1 file changed, 8 insertions(+), 3 deletions(-)
Code scan: clean
Tests: failed (timeout (120s))
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline