test(adr-110): lock the 9-second staleness gate on mesh_aligned_us_for_csi_frame
Iter 33 — closes a real test-coverage gap. The iter 17 staleness gate (returns None when latest_sync_at is older than 9 s = 3 × the firmware's VALID_WINDOW_MS) was shipped but never directly tested. A future careless edit changing `from_secs(9)` to e.g. `from_secs(90)` would silently break ADR-029/030 multistatic fusion freshness guarantees. Test (3 assertions, no sleep — uses `Instant::checked_sub` to set latest_sync_at to past values directly): * 1 s old → Some (fresh) * 8 s old → Some (just inside the gate) * 10 s old → None (just outside the gate) If anyone widens or narrows the gate, exactly one of these assertions fires and points at the off-by-one. Total time for the test < 1 ms. sync_snapshot_helper_tests: 6/6 green. Branch-coord clean — main.rs only. Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
parent
8805c8ec0b
commit
bea7edee1f
|
|
@ -5942,6 +5942,33 @@ mod sync_snapshot_helper_tests {
|
|||
assert_eq!(ns.latest_sync_at, Some(t1)); // staleness clock reset
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mesh_aligned_us_honors_9s_staleness_gate() {
|
||||
// The receive helper stores latest_sync_at = Instant::now() each
|
||||
// beacon. mesh_aligned_us_for_csi_frame returns None once that
|
||||
// Instant is older than 9 s (3 × VALID_WINDOW_MS). Verify both
|
||||
// sides of that boundary without sleeping — set latest_sync_at
|
||||
// to past instants directly.
|
||||
let mut ns = NodeState::new();
|
||||
let now = std::time::Instant::now();
|
||||
ns.latest_sync = Some(populated_sync(9));
|
||||
|
||||
// Fresh: 1 s old → should return Some.
|
||||
ns.latest_sync_at = now.checked_sub(std::time::Duration::from_secs(1));
|
||||
assert!(ns.mesh_aligned_us_for_csi_frame(20).is_some(),
|
||||
"1 s old sync must produce a mesh-aligned timestamp");
|
||||
|
||||
// Just inside the gate: 8 s old → should still return Some.
|
||||
ns.latest_sync_at = now.checked_sub(std::time::Duration::from_secs(8));
|
||||
assert!(ns.mesh_aligned_us_for_csi_frame(20).is_some(),
|
||||
"8 s old sync must still be inside the 9 s gate");
|
||||
|
||||
// Just outside the gate: 10 s old → must return None.
|
||||
ns.latest_sync_at = now.checked_sub(std::time::Duration::from_secs(10));
|
||||
assert!(ns.mesh_aligned_us_for_csi_frame(20).is_none(),
|
||||
"10 s old sync must trigger the 9 s staleness gate");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn snapshot_reflects_leader_state() {
|
||||
// Same data shape that /api/v1/mesh emits for a leader node.
|
||||
|
|
|
|||
Loading…
Reference in New Issue