summaryrefslogtreecommitdiffstats
path: root/tests/production_surface.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/production_surface.rs')
-rw-r--r--tests/production_surface.rs48
1 files changed, 48 insertions, 0 deletions
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"
+ );
+}