GPU tests: verify frame waits without scheduler assumptions #976

Open
avt0m4t48 wants to merge 1 commit from upstream-pr/978 into main
avt0m4t48 commented 2026-11-25 14:34:28 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by avt0m4t48 on 2026-11-25T14:34:28Z.


The frame-wait test can fail when the runner is descheduled. It expects a wait to finish within 50 ms of wall time and every flip to use an adjacent 5 ms tick. The frame clock can legitimately skip ticks when work is delayed. This was also reported in #970.

Keep checking the actual wait calls, timeouts, frame tokens, and strict increase in flip ticks. Move the exact timing assertions to a test of the existing next-tick calculation using fixed elapsed times. It covers phase, an early wake and a missed tick.

The original fixture failed with either a 65 ms pause at the upper wall-clock bound or 20 ms pauses before flip waits. The patched tests passed with both controls. A mutation that ignored the previous tick failed the new clock test. Both tests passed on native Windows in the default and legacy late-wait modes. The asset policy passed.

This covers the sequential tests. The concurrent title-wait behavior addressed by #325 is separate.

Windows verification

AI-assisted using Codex.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6606901145 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/978). Originally posted by [avt0m4t48](https://github.com/avt0m4t48) on 2026-11-25T14:34:28Z. --- The frame-wait test can fail when the runner is descheduled. It expects a wait to finish within 50 ms of wall time and every flip to use an adjacent 5 ms tick. The frame clock can legitimately skip ticks when work is delayed. This was also reported in #970. Keep checking the actual wait calls, timeouts, frame tokens, and strict increase in flip ticks. Move the exact timing assertions to a test of the existing next-tick calculation using fixed elapsed times. It covers phase, an early wake and a missed tick. The original fixture failed with either a 65 ms pause at the upper wall-clock bound or 20 ms pauses before flip waits. The patched tests passed with both controls. A mutation that ignored the previous tick failed the new clock test. Both tests passed on native Windows in the default and legacy late-wait modes. The asset policy passed. This covers the sequential tests. The concurrent title-wait behavior addressed by #325 is separate. [Windows verification](https://github.com/avt0m4t48/victory-fork/actions/runs/45634545885) AI-assisted using Codex.
HailLucifer666 commented 2026-11-25 16:12:51 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by HailLucifer666 on 2026-11-25T15:20:29Z.


Same flake, independently measured tonight on Windows 10: 1 failure in 12 whole-binary runs at four-way process load, 0 in 16 serial, 0 in 24 with the test run alone. Your reading is right, and I want to add one mechanism note plus an alternative I have ready but have not opened as a PR, so you are not asked to review two things at once.

Why it fails. The assertion is before.elapsed() <= 50 ms wrapped around two 2 ms waits, plus "every flip lands on the adjacent tick". Both are claims about the machine waking up on time. Nothing in frame fails; the test measures the scheduler.

What I did differently. frame now gets its time and its sleeping from one swappable ClockSource — Instant::now and thread::sleep in the title, a hand-driven clock in tests — so the assertions become exact numbers about the arithmetic instead of wall clock:

  • each origin wait ends on the tick after the last one;
  • two 2 ms waits cost exactly 4 ms, and a timeout_ms = 0 poll after them costs none;
  • four flips are four consecutive ticks;
  • the whole run costs exactly 21 ms — and it is 21, not 26, because the first flip ends immediately when the clock is already past its tick, which is the late-wait shortcut doing its job. The sum makes that visible instead of leaving it as a comment.

The test then finishes in 0.00 s and never sleeps. Probes: make the next tick the current tick (elapsed / interval + 1 → elapsed / interval) → fails 16 ms vs 21 ms; sleep 1 us short of the tick → fails 3.999 ms vs 4 ms.

The trade, plainly. Mine adds a seam to shipping code (frame.rs, two functions and one OnceLock); yours touches tests only. Yours removes the unsound assertion; mine replaces it with a stronger one. If the owner prefers test-only, take yours and I will not open mine — say the word either way and I'll follow your call rather than adding a second PR to the queue.

One thing worth keeping from the current test whichever version lands: assert!(LAST[0] >= 2) and the "a poll costs no time" check are the parts that catch a real regression. The 50 ms and tick-adjacency checks are the parts that cannot.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7166689137 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/978#issuecomment-7166689137). Originally posted by [HailLucifer666](https://github.com/HailLucifer666) on 2026-11-25T15:20:29Z. --- Same flake, independently measured tonight on Windows 10: **1 failure in 12** whole-binary runs at four-way process load, **0 in 16** serial, **0 in 24** with the test run alone. Your reading is right, and I want to add one mechanism note plus an alternative I have ready but have **not** opened as a PR, so you are not asked to review two things at once. **Why it fails.** The assertion is `before.elapsed() <= 50 ms` wrapped around two 2 ms waits, plus "every flip lands on the adjacent tick". Both are claims about the machine waking up on time. Nothing in `frame` fails; the test measures the scheduler. **What I did differently.** `frame` now gets its time and its sleeping from one swappable `ClockSource` — `Instant::now` and `thread::sleep` in the title, a hand-driven clock in tests — so the assertions become exact numbers about the arithmetic instead of wall clock: - each origin wait ends on the tick after the last one; - two 2 ms waits cost exactly 4 ms, and a `timeout_ms = 0` poll after them costs none; - four flips are four consecutive ticks; - the whole run costs exactly **21 ms** — and it is 21, not 26, because the first flip ends immediately when the clock is already past its tick, which is the late-wait shortcut doing its job. The sum makes that visible instead of leaving it as a comment. The test then finishes in 0.00 s and never sleeps. Probes: make the next tick the current tick (`elapsed / interval + 1` → `elapsed / interval`) → fails 16 ms vs 21 ms; sleep 1 us short of the tick → fails 3.999 ms vs 4 ms. **The trade, plainly.** Mine adds a seam to shipping code (`frame.rs`, two functions and one `OnceLock`); yours touches tests only. Yours removes the unsound assertion; mine replaces it with a stronger one. If the owner prefers test-only, take yours and I will not open mine — say the word either way and I'll follow your call rather than adding a second PR to the queue. One thing worth keeping from the current test whichever version lands: `assert!(LAST[0] >= 2)` and the "a poll costs no time" check are the parts that catch a real regression. The 50 ms and tick-adjacency checks are the parts that cannot.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/978:upstream-pr/978'
git switch 'upstream-pr/978'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/978'
git switch 'upstream-pr/978'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/978'
git switch 'upstream-pr/978'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/978'
git switch 'main'
git merge --squash 'upstream-pr/978'
git switch 'main'
git merge --ff-only 'upstream-pr/978'
git switch 'main'
git merge 'upstream-pr/978'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
fxceless/victory-fork!976
No description provided.