timer: delay_for should use tokio_timer::clock::now (#1572)

This commit is contained in:
Markus Westerlind 2019-09-19 20:20:18 +02:00 committed by Carl Lerche
parent 9d5af20bcf
commit 34e388619f
3 changed files with 13 additions and 3 deletions

View File

@ -40,7 +40,7 @@ impl Interval {
/// Creates new `Interval` that yields with interval of `duration`.
///
/// The function is shortcut for `Interval::new(Instant::now() + duration, duration)`.
/// The function is shortcut for `Interval::new(tokio_timer::clock::now() + duration, duration)`.
///
/// The `duration` argument must be a non-zero duration.
///

View File

@ -70,9 +70,9 @@ pub fn delay(deadline: Instant) -> Delay {
/// Create a Future that completes in `duration` from now.
///
/// Equivalent to `delay(Instant::now() + duration)`. Analogous to `std::thread::sleep`.
/// Equivalent to `delay(tokio_timer::clock::now() + duration)`. Analogous to `std::thread::sleep`.
pub fn delay_for(duration: Duration) -> Delay {
delay(Instant::now() + duration)
delay(clock::now() + duration)
}
// ===== Internal utils =====

View File

@ -47,3 +47,13 @@ fn clock_and_timer_single_threaded() {
assert!(Instant::now() < when);
});
}
#[test]
fn mocked_clock_delay_for() {
tokio_test::clock::mock(|handle| {
let mut f = tokio_test::task::spawn(delay_for(Duration::from_millis(1)));
tokio_test::assert_pending!(f.poll());
handle.advance(Duration::from_millis(1));
tokio_test::assert_ready!(f.poll());
});
}