From 60fbbcb4e54d939304bb97759dcab23a75b00f50 Mon Sep 17 00:00:00 2001 From: Ayoze Torres <53948812+ayozetr@users.noreply.github.com> Date: Tue, 27 Oct 2026 18:15:27 +0000 Subject: [PATCH] Run-loop tests: take t0 before registering the timers A timer's first tick is set at registration, so taking the reference time afterwards made the "not due yet" check depend on the test thread not stalling for a timer period (1 ms in the CLAP test). Same pattern fixed in the VST3 test. --- crates/clap-host/src/ffi/run_loop.rs | 3 ++- crates/vst3-host/src/ffi/editor.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/clap-host/src/ffi/run_loop.rs b/crates/clap-host/src/ffi/run_loop.rs index 602d505f8..b15686e11 100644 --- a/crates/clap-host/src/ffi/run_loop.rs +++ b/crates/clap-host/src/ffi/run_loop.rs @@ -157,10 +157,11 @@ mod tests { #[test] fn timers_and_descriptors_follow_registration() { let rl = RunLoop::default(); + // Before registering: every timer's first tick is then later than `t0`. + let t0 = Instant::now(); let a = rl.add_timer(10).unwrap(); let b = rl.add_timer(0).unwrap(); assert_ne!(a, b, "ids are unique"); - let t0 = Instant::now(); assert!(rl.due(t0).is_empty(), "not due yet"); let mut due = rl.due(t0 + Duration::from_secs(1)); due.sort_unstable(); diff --git a/crates/vst3-host/src/ffi/editor.rs b/crates/vst3-host/src/ffi/editor.rs index 7cf94ead6..72c3b1edd 100644 --- a/crates/vst3-host/src/ffi/editor.rs +++ b/crates/vst3-host/src/ffi/editor.rs @@ -395,6 +395,8 @@ mod tests { let ticks = ComWrapper::new(Ticks::default()); let timer = ticks.as_com_ref::().unwrap().as_ptr(); let handler = ticks.as_com_ref::().unwrap().as_ptr(); + // Before registering: every timer's first tick is then later than `t0`. + let t0 = Instant::now(); let mut fds = [0; 2]; // SAFETY: `fds` holds the two descriptors `pipe` writes. assert_eq!(unsafe { libc::pipe(fds.as_mut_ptr()) }, 0); @@ -405,7 +407,6 @@ mod tests { assert_ne!(rl.registerEventHandler(handler, -1), sb::kResultOk); assert_ne!(rl.registerTimer(std::ptr::null_mut(), 10), sb::kResultOk); } - let t0 = Instant::now(); frame.run_loop.dispatch(t0); assert_eq!(ticks.timer.load(Ordering::Relaxed), 0, "not due yet"); assert_eq!(ticks.fd.load(Ordering::Relaxed), 0, "nothing to read");