blob: d1607ba3f57ca4452c59a86b4235e21dc8c76284 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#![deny(warnings, rust_2018_idioms)]
#![cfg(feature = "broken")]
use std::time::Instant;
use tokio_executor;
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);
let mut enter = tokio_executor::enter().unwrap();
with_default(&clock, &mut enter, |_| {
let a = Instant::now();
let b = clock::now();
assert!(b <= a);
});
}
|