Files
tokio/tokio-timer/tests/clock.rs
T
Carl LercheandGitHub b2c777846e timer: finish updating timer (#1222)
* timer: restructure feature flags
* update timer tests
* Add `async-traits` to CI

This also disables a buggy `threadpool` test. This test should be fixed in the future.

Refs #1225
2019-06-30 08:48:53 -07:00

48 lines
814 B
Rust

#![deny(warnings, rust_2018_idioms)]
use std::time::Instant;
use tokio_timer::clock;
use tokio_timer::clock::*;
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);
});
}