diff --git a/crates/scheduler/src/test_scheduler.rs b/crates/scheduler/src/test_scheduler.rs index 1f2197a13d8bfc2dae1693a4da102dd6324b3919..243f6f756df15f9b05b87ec70b37c1392f60c57d 100644 --- a/crates/scheduler/src/test_scheduler.rs +++ b/crates/scheduler/src/test_scheduler.rs @@ -176,9 +176,18 @@ impl TestScheduler { } pub fn advance_clock(&self, duration: Duration) { - self.run(); - self.clock.advance(duration); - self.run(); + let next_now = self.clock.now() + duration; + loop { + self.run(); + if let Some(timer) = self.state.lock().timers.first() + && timer.expiration <= next_now + { + self.clock.advance(timer.expiration - self.clock.now()); + } else { + break; + } + } + self.clock.advance(next_now - self.clock.now()); } fn park(&self, deadline: Option) -> bool {