mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-09-28 12:10:37 +00:00

A step towards collapsing Tokio sub crates into a single `tokio` crate (#1318). The `timer` implementation is now provided by the main `tokio` crate. The `timer` functionality may still be excluded from the build by skipping the `timer` feature flag.
26 lines
570 B
Rust
26 lines
570 B
Rust
#![warn(rust_2018_idioms)]
|
|
|
|
use tokio::timer::delay;
|
|
use tokio_test::clock::MockClock;
|
|
use tokio_test::task;
|
|
use tokio_test::{assert_pending, assert_ready};
|
|
|
|
use std::time::{Duration, Instant};
|
|
|
|
#[test]
|
|
fn clock() {
|
|
let mut mock = MockClock::new();
|
|
|
|
mock.enter(|handle| {
|
|
let deadline = Instant::now() + Duration::from_secs(1);
|
|
let mut delay = task::spawn(delay(deadline));
|
|
|
|
assert_pending!(delay.poll());
|
|
|
|
handle.advance(Duration::from_secs(2));
|
|
|
|
assert!(delay.is_woken());
|
|
assert_ready!(delay.poll());
|
|
});
|
|
}
|