From b9a64de05024eb41b1db79c45593b48ef7a46b23 Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Tue, 1 Dec 2026 02:20:13 +0800 Subject: [PATCH] test(memory): make the debounce test tolerate a loaded machine --- crates/ide-core/src/memory.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/crates/ide-core/src/memory.rs b/crates/ide-core/src/memory.rs index 18d6651b0..61f59cc29 100644 --- a/crates/ide-core/src/memory.rs +++ b/crates/ide-core/src/memory.rs @@ -63,13 +63,30 @@ mod tests { #[test] fn a_burst_of_calls_runs_once_after_the_delay() { + // Timing-based: a loaded CI machine can oversleep, so each check allows for that. + let delay = Duration::from_millis(500); + let (mut last, mut widest_gap) = (None::, Duration::ZERO); for _ in 0..5 { - debounce(&DUE, Duration::from_millis(100), count); + debounce(&DUE, delay, count); + let now = Instant::now(); + widest_gap = widest_gap.max(last.map_or(Duration::ZERO, |l| now - l)); + last = Some(now); std::thread::sleep(Duration::from_millis(20)); } - assert_eq!(RUNS.load(SeqCst), 0); - std::thread::sleep(Duration::from_millis(400)); - assert_eq!(RUNS.load(SeqCst), 1); + if last.unwrap().elapsed() < delay { + assert_eq!(RUNS.load(SeqCst), 0, "ran before the delay passed"); + } + let deadline = Instant::now() + Duration::from_secs(10); + while RUNS.load(SeqCst) == 0 && Instant::now() < deadline { + std::thread::sleep(Duration::from_millis(10)); + } + // A second run would come within another delay. + std::thread::sleep(delay); + if widest_gap < delay { + assert_eq!(RUNS.load(SeqCst), 1); + } else { + assert!(RUNS.load(SeqCst) >= 1); + } release_free_pages_soon(); } }