From f1b910da4e11321aed8f406a89a59b5f9db34054 Mon Sep 17 00:00:00 2001 From: KKRainbow <5665404+KKRainbow@users.noreply.github.com> Date: Sun, 18 Oct 2026 12:36:54 +0800 Subject: [PATCH] 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. --- easytier-core/src/tunnel/secure_datagram.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/easytier-core/src/tunnel/secure_datagram.rs b/easytier-core/src/tunnel/secure_datagram.rs index db118a07..181f80bd 100644 --- a/easytier-core/src/tunnel/secure_datagram.rs +++ b/easytier-core/src/tunnel/secure_datagram.rs @@ -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]