test: make secure datagram grace expiry deterministic (#2723)

The expiry test sampled time before sync_root_key established its grace
period. Scheduling delays over 3 ms could leave the asserted timestamp
inside the grace window and fail the test.

Use the actual grace deadline to check acceptance just before expiry and
rejection at expiry. Use a fresh sequence number for the rejection check
so replay detection cannot hide a broken expiry boundary.
This commit is contained in:
KKRainbow
2026-10-18 12:36:54 +08:00
committed by GitHub
parent e25c6bdd0c
commit f1b910da4e
+5 -7
View File
@@ -1011,14 +1011,12 @@ mod tests {
assert!(s.check_replay_for_test(1, 0, SecureDatagramDirection::AToB, now + 1));
s.sync_root_key(root_key, 2, 2, true);
assert!(s.check_replay_for_test(2, 0, SecureDatagramDirection::AToB, now + 2));
// Use the actual deadline so scheduling delays before sync do not affect the test.
let expires_at_ms = s.sync_rx_grace_expires_at_ms.load(Ordering::Relaxed);
assert!(s.check_replay_for_test(2, 0, SecureDatagramDirection::AToB, expires_at_ms - 1));
assert!(s.check_replay_for_test(0, 1, SecureDatagramDirection::AToB, expires_at_ms - 1));
assert!(!s.check_replay_for_test(
0,
1,
SecureDatagramDirection::AToB,
now + SecureDatagramSession::SYNC_RX_GRACE_AFTER_MS + 3
));
assert!(!s.check_replay_for_test(0, 2, SecureDatagramDirection::AToB, expires_at_ms));
}
#[test]