From 768da4fd62b390014fcaf55e23dbb45ca61ad79b Mon Sep 17 00:00:00 2001 From: aur-build Date: Thu, 19 Nov 2026 19:50:24 +0000 Subject: time: a wait seam the control loops call through The dispatcher tick, watcher tick, SSE poll, agent watchdog and remote keepalive each slept on the wall clock in their own slice loop, so every test that wanted a tick waited for real time. They call crate::time::wait/sleep now, which is the same real sleep in a production build and a virtual clock advance under test-support: a test that takes the clock owns it, and threads it spawns inherit it. production_surface checks the virtual path is compiled out and that no control loop went back to std::thread::sleep. --- tests/production_surface.rs | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'tests') diff --git a/tests/production_surface.rs b/tests/production_surface.rs index 214fbc6..038a036 100644 --- a/tests/production_surface.rs +++ b/tests/production_surface.rs @@ -153,3 +153,51 @@ fn audit_rows_are_built_by_the_constructors_not_by_hand() { assert!(!src.contains("db::AuditEntry {"), "audit rows must be built by AuditEntry::human/system"); assert_eq!(src.matches("AuditEntry::human(").count(), 3, "approve, reject and withdraw"); } + +#[test] +fn the_virtual_clock_is_compiled_out_without_test_support() { + let src = read("src/time.rs"); + assert!( + src.contains("#[cfg(feature = \"test-support\")]"), + "the virtual clock must be behind the test-support feature" + ); + let fallback = src + .split("#[cfg(not(feature = \"test-support\"))]") + .nth(1) + .expect("without test-support there must be a clock module that is always real"); + assert!( + fallback.contains("pub fn advance(_d: Duration) -> bool") && fallback.contains("false"), + "the fallback advance() must be a constant false so the seam compiles to a plain sleep" + ); + assert!( + !fallback.contains("Mutex"), + "nothing may be locked on the wait path of a production build" + ); +} + +#[test] +fn control_loops_wait_through_the_clock_seam() { + for file in [ + "src/pipeline/dispatch.rs", + "src/watch/scheduler.rs", + "src/http/sse.rs", + "src/sandbox/remote.rs", + ] { + let src = read(file); + assert!( + !src.contains("std::thread::sleep"), + "{file} waits on the wall clock; go through crate::time so a test can drive it" + ); + assert!( + src.contains("crate::time::wait") || src.contains("crate::time::sleep"), + "{file} never reaches the clock seam" + ); + } + let agent = read("src/sandbox/agent.rs"); + assert!(agent.contains("crate::time::sleep"), "the watchdog must use the seam"); + assert_eq!( + agent.matches("std::thread::sleep").count(), + 1, + "only the hub connect retry may sleep on the wall clock: it runs in the agent binary, which has no test-support to virtualize" + ); +} -- cgit v1.2.3