Skip to content

CI: tests that failed at random on a busy runner - #83

Merged
Dyotson merged 2 commits into
mainfrom
ci/flaky-tests-timing
Nov 24, 2026
Merged

Dyotson merged 2 commits into
mainfrom
ci/flaky-tests-timing

Conversation

@Dyotson

@Dyotson Dyotson commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Tests in this repo failed at random in CI and passed on a re-run. This makes them deterministic.

LiveSizeTest (scores, notifications) and friends LoopTest: "Executing <Task ...> took 0.337 seconds"
Cause: asyncio's slow-callback warning measures wall time. On a busy runner the process is simply not scheduled for a while, so a 3 ms step "took" 300+ ms. Seen on #80's run, and on earlier runs on main and in PRs (Linux and Windows, 3.12 and 3.14); more tests in the same classes fail the same way under load.
Fix: new tests/support.loop_steps_under(limit) measures the CPU time of every loop step (thread CPU time), which is the same on a quiet machine and a busy one; the wall-time warning is switched off in those tests. The took timings in the same tests use CPU time too. The limits (0.05 / 0.25 s) and the checks that the whole file is never written on the loop thread are unchanged. Waits that use no CPU (a journal flush, a lock the writing thread holds, a tick that sleeps) are covered by wall-time medians: the median of the timed calls (scores, notifications) must be under 0.05 s, a new friends test takes the median of 5 ticks (under 0.25 s), and the wake-up lag check is now a median too (it was the worst one, which a descheduled process fails). A median of 25-41 calls is not moved by a few calls the runner did not schedule, but a wait on every call is; the worst single call is measured in CPU time only. In the slow-disk test a loop that waits for the writing thread now fails the test after 30 s instead of hanging. tests/core/test_loop_steps.py tests the helper.
Loops (6 busy processes at nice 19, 2 runs at a time, the three classes): before 3 failures in 24 runs (with a heavier load: nearly every run); after 0 in 14 runs. With the process stopped (SIGSTOP) for 0.34 s every 0.7 s, and 0.4 s every 0.3 s, 3 runs each of the three classes pass after the change (main failed 2 of 3 in the first case). Mutations (the change made again in the server source: whole file on the loop, unguarded whole-file write, the journal flush or the friends tick blocking the loop 300 ms, the loop waiting for the checkpoint lock, the disk walk on the loop) are all caught.

test_relay_processes: "the relay did not link" (failed once on a game repo PR run, passed on re-run)
Cause: the test started the main server and the relay at once. When the main server is still starting on a slow runner, the relay's first link is lost and it retries only every 5 s, and the 30 s limit also had to cover both process starts. The child logs were thrown away, so nothing showed it.
Fix: the test waits until the main server answers /status and the relay has logged that it runs, then the 30 s link limit starts; the same after the main server's restart. The server logs are kept and printed when a wait fails. I could not make the old test fail here (52 runs under load passed), so this cause is from reading the code and the log, not proven by a failing loop; after: see the runs below.

Full suite on 3.12 and 3.14: 1271 tests OK.

@Dyotson Dyotson self-assigned this Nov 24, 2026
@Dyotson
Dyotson merged commit d65237a into main Nov 24, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant