Skip to content

test(core): freeze the wait clock in two timeout tests and let the scheduler sleep on it - #49

Merged
gshost1 merged 4 commits into
mainfrom
test/wait-event-frozen-clock
Nov 8, 2026
Merged

gshost1 merged 4 commits into
mainfrom
test/wait-event-frozen-clock

Conversation

@gshost1

@gshost1 gshost1 commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

What and why

Update after merging main: #45 (24574e9) already froze the clock in failed_inventory_poll_never_diffs_against_an_empty_baseline. Against main this PR now changes two lines. It freezes the clock in retryable_seed_inventory_failure_is_preserved_in_timeout_evidence, and it makes WaitScheduler::wait sleep on the test-aware clock, which that freeze needs (without it the test loops forever).

Two wait_event tests set a 20 ms deadline on the wall clock and then asserted on the last poll error:

  • failed_inventory_poll_never_diffs_against_an_empty_baseline
  • retryable_seed_inventory_failure_is_preserved_in_timeout_evidence

On a loaded runner the deadline passed before the first poll, so last_error was null. This failed the macOS Test job on #6 (9637e8b), which doesn't touch this code. Main had passed the same test on 921d6d2.

Both tests now freeze the virtual clock, as their neighbour failed_inventory_poll_never_reports_app_termination already does.

Freezing exposed a second problem: WaitScheduler::wait slept with std::thread::sleep, so virtual time never advanced and the frozen test looped forever. It now sleeps through wait::deadline::sleep. Outside cfg(test) that function is std::thread::sleep, so shipped behaviour is unchanged.

How tested

All runs went through the bench's serialized cargo wrapper on macOS.

  • cargo build --tests -p agent-desktop-core: ok.
  • cargo test -p agent-desktop-core --lib wait: 289 passed, 0 failed.
  • cargo clippy -p agent-desktop-core --all-targets -- -D warnings: clean.
  • cargo fmt --all -- --check: clean.
  • check-rust-file-size.sh, check-no-phase-references.sh, check-stale-ref-constructor-misuse.sh and check-architecture.sh: pass.
  • Invert check: with the scheduler change reverted, retryable_seed_inventory_failure_is_preserved_in_timeout_evidence hangs. It ran past 60 s and was stopped at 1200 s. With the change restored, 36 wait_event tests pass in 1.08 s.
  • The original race can't be reproduced on demand. The fix replaces the wall clock in these tests, so the race can't occur.

Risks

  • WaitScheduler::wait now calls wait::deadline::sleep. Non-test builds compile it to the same std::thread::sleep.
  • Other tests that freeze the clock and reach the scheduler now advance virtual time instead of sleeping for real. All 289 wait tests pass.

Left

Nothing.

…heduler sleep on it

Two wait_event tests gave wait_for_event a 20 ms deadline on the wall clock and
then asserted on the last poll error. On a loaded runner the deadline passed
before the first poll, so last_error was null (fork CI on 9637e8b). Both now
freeze the virtual clock, as their neighbour already does.

Freezing exposed that WaitScheduler::wait slept with std::thread::sleep, so
virtual time never advanced and the test looped. It now sleeps through
wait::deadline::sleep, which is std::thread::sleep outside tests, so shipped
behaviour is unchanged.
@gshost1
gshost1 merged commit d009162 into main Nov 8, 2026
13 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