From ccf9b13e04537faff1a4431945ae62bd0ddd7894 Mon Sep 17 00:00:00 2001 From: Razvan Dimescu Date: Wed, 1 Apr 2026 12:07:19 +0300 Subject: [PATCH] fix: SRTT decay tests panic on Windows due to Instant underflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Windows, Instant starts near boot time — subtracting large durations panics. Use checked_sub with a process-start fallback. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/srtt.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/srtt.rs b/src/srtt.rs index bfad115..a832f99 100644 --- a/src/srtt.rs +++ b/src/srtt.rs @@ -218,8 +218,14 @@ mod tests { assert_eq!(addrs, original); } + // On Windows, Instant starts near boot time — large subtractions overflow. + // Fall back to a fixed reference point created at process start. + static EPOCH: std::sync::OnceLock = std::sync::OnceLock::new(); + fn age(secs: u64) -> Instant { - Instant::now() - std::time::Duration::from_secs(secs) + Instant::now() + .checked_sub(std::time::Duration::from_secs(secs)) + .unwrap_or(*EPOCH.get_or_init(Instant::now)) } /// Cache with ip(1) saturated at FAILURE_PENALTY_MS