Macro tokio_test::assert_elapsed
source · macro_rules! assert_elapsed { ($start:expr, $dur:expr) => { ... }; }
Expand description
Asserts that an exact duration has elapsed since the start instant ±1ms.
use tokio::time::{self, Instant};
use std::time::Duration;
use tokio_test::assert_elapsed;
let start = Instant::now();
let dur = Duration::from_millis(50);
time::sleep(dur).await;
assert_elapsed!(start, dur);
This 1ms buffer is required because Tokio’s hashed-wheel timer has finite time resolution and will not always sleep for the exact interval.