Skip to content

test: settle the align-divisor phase before stop, so the Fast Gate stops flaking (#2957) - #2958

Merged
zackees merged 1 commit into
masterfrom
fix/2957-align-divisor-flake
Oct 29, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/2957-align-divisor-flake

Conversation

@zackees

@zackees zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member

align_divisor_restarts_the_phase (from #2926) races video_output_stop, so master's Fast Gate fails at random and takes unrelated PRs with it — my #2951 failed on it while touching only macOS frontend files (run 40936499568, job 123669886573, left: 3, right: 4 at rust/obs-media-io/tests/video/video_io.rs:600).

RED (master 61c814e48, before this PR)

The test pushes 2000, 3000 and 4000 back to back and waits only for the 3000 delivery, so video_output_stop can set the stop flag while 4000 is still in the cache slot; the video thread breaks at its if shared.stop check before it takes that frame, and video_output_get_total_frames reads 3 instead of 4.

$ soldr cargo test -p obs-media-io --lib && for i in $(seq 1 60); do obs_media_io-99d375fde0aeb566 --exact \
    tests::video::video_io::align_divisor_restarts_the_phase; done
fails=18/60
thread 'tests::video::video_io::align_divisor_restarts_the_phase' panicked at
rust/obs-media-io/tests/video/video_io.rs:600:14:
assertion `left == right` failed
  left: 3
 right: 4

40 runs of the whole tests::video::video_io module produced this test and no other failure, so the rest of the module is not racy.

C's video_output_stop has the same property: a frame still queued when the stop flag is set is dropped. The port is right and the test was over-asserting, so the fix belongs in the test.

GREEN

Session::settle(total) waits (2 s bound, yield_now, no sleeps — it is the same condvar/no sleeps harness the file already uses) for the video thread to finish the frames pushed so far; align_divisor_restarts_the_phase calls settle(4) after its last wait_hits(2) and before the stop. The assertion on total == 4 is unchanged, and a frame that never gets processed still fails: the settle panics naming the observed count.

$ soldr cargo test -p obs-media-io --lib
test result: ok. 282 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 8.65s

$ for i in $(seq 1 200); do obs_media_io-99d375fde0aeb566 --exact \
    tests::video::video_io::align_divisor_restarts_the_phase; done
fails=0/200

./lint passes (177 s, lane lint: ok).

No user-visible change, so no docs/features.md line. Tier 1 only: the change is test synchronization in the Rust test harness, no libobs behavior, C test or public header is touched.

Fixes #2957

`align_divisor_restarts_the_phase` pushed 2000, 3000 and 4000 back to back
and waited only for the 3000 delivery, so `video_output_stop` could set the
stop flag while 4000 was still queued. The video thread then breaks before it
takes that frame and `video_output_get_total_frames` reads 3: 18 of 60 runs
failed on master 61c814e, reddening the Fast Gate of unrelated PRs.

`Session::settle` waits, with a 2 s bound, for the video thread to finish the
frames pushed so far, before the stop. C's `video_output_stop` also drops a
frame still queued at shutdown, so the test, not the port, was racing.

Fixes #2957

@zackees zackees left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed as coordinator (no approval possible on the maintainer's own PR; verdict below).

Verdict: correct, merge when checks finish.

  • The diagnosis matches the code: the test pushes 1000/2000/3000/4000 and only waits for the 3000 delivery, so video_output_stop can set the stop flag while 4000 is still in the cache slot, and the video thread breaks before it takes it, leaving video_output_get_total_frames at 3. C's video_output_stop drops a still-queued frame the same way, so the port is right and the assertion was racing the stop — the fix belongs in the test, as done here.
  • settle(total) polls the real counter with yield_now and a 2 s bound, and panics with the observed count. That preserves the RED property: if the implementation ever genuinely drops the fourth frame (rather than the test calling stop too early), settle(4) fails naming the count instead of silently passing.
  • Bound is ample: the harness runs at 30 fps (rgba_info), so four frames are ~133 ms against 2 s; wait_hits(2) has already ordered the deliveries before settle runs.
  • The assertion set is unchanged (hits.n == 2, timestamps, total_frames == 4), so no coverage was loosened, and no libobs behaviour, C test or public header is touched — Tier 1 only, no docs/features.md line needed. Import of Duration/Instant is minimal and in the file's existing style.

Nit, not blocking: settle is a busy-poll where the rest of the harness is condvar-driven, because the frame counter isn't behind that mutex. Fine as is; if another test needs it later, a small Condvar-signalled counter would keep the "no sleeps, no spinning" property uniform.

Queuing once the Fast Gate job completes; the merge gate is PR CI plus the queue.

@zackees
zackees added this pull request to the merge queue Oct 29, 2026
@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Handed off to the coordinator — #2958 is in the merge queue (position 1, AWAITING_CHECKS) with CI Gate ✅ on the PR head and Fast Gate ⚡ green (12m13s, the lane that was flaking).

Local evidence on the head: soldr cargo test -p obs-media-io --lib → 282 passed; 200 isolated runs of align_divisor_restarts_the_phase → 0 failures (18/60 failed on master); ./lint ok. I did not stamp HEAD with the local gate (the change is test-only), so the queue rerun is the gate.

Merged via the queue into master with commit b25c5eb Oct 29, 2026
35 checks passed
@zackees
zackees deleted the fix/2957-align-divisor-flake branch October 29, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug: test: align_divisor_restarts_the_phase races video_output_stop and reddens the Fast Gate on ~30% of runs

1 participant