Files
tokio/tokio/tests/timer_clock.rs
T
Carl Lerche b8cee1a60a timer: move tokio-timer into tokio crate (#1674)
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.
2019-10-21 16:45:13 -07:00

49 lines
807 B
Rust

#![warn(rust_2018_idioms)]
use tokio::timer::clock;
use tokio::timer::clock::*;
use std::time::Instant;
struct ConstNow(Instant);
impl Now for ConstNow {
fn now(&self) -> Instant {
self.0
}
}
#[test]
fn default_clock() {
let a = Instant::now();
let b = clock::now();
let c = Clock::new().now();
assert!(a <= b);
assert!(b <= c);
}
#[test]
fn custom_clock() {
let now = ConstNow(Instant::now());
let clock = Clock::new_with_now(now);
let a = Instant::now();
let b = clock.now();
assert!(b <= a);
}
#[test]
fn execution_context() {
let now = ConstNow(Instant::now());
let clock = Clock::new_with_now(now);
with_default(&clock, || {
let a = Instant::now();
let b = clock::now();
assert!(b <= a);
});
}