Fix the flaky capture-loop test at its cause, not its timeout - #76
Merged
Merged
Conversation
test_refresh_failure_does_not_kill_capture_loop failed roughly 1 run in 20, on any machine, and took main red after an unrelated merge. It is not a slow runner and a longer timeout would not have helped. _run() only re-renders when new_frames_since_render > 0, and the first render resets that counter. The capture thread starts on service.start() and consumes frames every POLL_INTERVAL_S while the main thread is still on its way to attach(). With a fixed two-frame list there is a race: if both frames are gone before a viewer is registered, the first render fires on _refresh_requested, the counter resets, no frame ever arrives again, and the second render can never happen. calls["n"] sticks at 1 and the wait expires however long it is. The test now takes frames from a source that never runs out, so a second render is reachable whatever order the threads happen to run in. The assertion then tests what it means to test, that the loop survives an exception, rather than incidentally testing thread scheduling. FakeBlah2Client is left alone. Other tests assert on a fixed frame count and rely on it draining. Measured: 0 failures in 150 runs, against 2/25 and 2/50 before. Full suite 802 passing. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Why
test_refresh_failure_does_not_kill_capture_loopfails roughly 1 run in 20, on any machine. It tookmainred after an unrelated merge, and cost a re-run on #75 before that.It is not a slow runner, and raising the timeout would not have helped.
Cause
_run()only re-renders whennew_frames_since_render > 0, and the first render resets that counter:The capture thread starts on
service.start()and consumes frames everyPOLL_INTERVAL_Swhile the main thread is still on its way toattach(). With a fixed two-frame list there is a race: if both frames are gone before a viewer is registered, the first render fires on_refresh_requested, the counter resets, no frame ever arrives again, and the second render can never happen.calls["n"]sticks at 1 and the wait expires however long it is.Fix
The test now takes frames from a source that never runs out, so a second render is reachable whatever order the threads happen to run in. The assertion then tests what it means to test, that the loop survives an exception, rather than incidentally testing thread scheduling.
FakeBlah2Clientis deliberately left alone: other tests assert on a fixed frame count and rely on it draining.Measured
origin/mainFull suite: 802 passing.