Files
tokio/tokio-timer/tests/interval.rs
T

44 lines
984 B
Rust
Raw Normal View History

2019-05-14 10:27:36 -07:00
#![deny(warnings, rust_2018_idioms)]
#![cfg(feature = "broken")]
2018-03-28 22:26:47 -07:00
mod support;
2019-05-14 10:27:36 -07:00
use crate::support::*;
2018-03-28 22:26:47 -07:00
2019-02-21 11:56:15 -08:00
use futures::Stream;
2019-05-14 10:27:36 -07:00
use tokio_timer::*;
2018-03-28 22:26:47 -07:00
#[test]
#[should_panic]
fn interval_zero_duration() {
mocked(|_, time| {
let _ = Interval::new(time.now(), ms(0));
});
}
#[test]
fn usage() {
mocked(|timer, time| {
let start = time.now();
let mut int = Interval::new(start, ms(300));
assert_ready_eq!(int, Some(start));
2018-03-28 22:26:47 -07:00
assert_not_ready!(int);
advance(timer, ms(100));
assert_not_ready!(int);
advance(timer, ms(200));
assert_ready_eq!(int, Some(start + ms(300)));
2018-03-28 22:26:47 -07:00
assert_not_ready!(int);
advance(timer, ms(400));
assert_ready_eq!(int, Some(start + ms(600)));
2018-03-28 22:26:47 -07:00
assert_not_ready!(int);
advance(timer, ms(500));
assert_ready_eq!(int, Some(start + ms(900)));
assert_ready_eq!(int, Some(start + ms(1200)));
2018-03-28 22:26:47 -07:00
assert_not_ready!(int);
});
}