mirror of
https://github.com/storytold/soundcraft.git
synced 2026-12-02 10:37:29 -06:00
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.
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -395,6 +395,8 @@ mod tests {
|
||||
let ticks = ComWrapper::new(Ticks::default());
|
||||
let timer = ticks.as_com_ref::<sb::Linux::ITimerHandler>().unwrap().as_ptr();
|
||||
let handler = ticks.as_com_ref::<sb::Linux::IEventHandler>().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");
|
||||
|
||||
Reference in New Issue
Block a user