diff --git a/ntex/src/time/mod.rs b/ntex/src/time/mod.rs index fc40b87b..a3286cbd 100644 --- a/ntex/src/time/mod.rs +++ b/ntex/src/time/mod.rs @@ -193,6 +193,7 @@ impl crate::Stream for Interval { #[cfg(test)] mod tests { use super::*; + use futures::StreamExt; use std::time; /// State Under Test: Two calls of `now()` return the same value if they are done within resolution interval. @@ -245,4 +246,29 @@ mod tests { assert!(second_time - first_time >= time::Duration::from_millis(wait_time)); } + + #[crate::rt_test] + async fn test_interval() { + let mut int = interval(Millis(250)); + + let time = time::Instant::now(); + int.tick().await; + let elapsed = time::Instant::now() - time; + assert!( + elapsed > time::Duration::from_millis(200) + && elapsed < time::Duration::from_millis(300), + "elapsed: {:?}", + elapsed + ); + + let time = time::Instant::now(); + int.next().await; + let elapsed = time::Instant::now() - time; + assert!( + elapsed > time::Duration::from_millis(200) + && elapsed < time::Duration::from_millis(300), + "elapsed: {:?}", + elapsed + ); + } } diff --git a/ntex/src/time/wheel.rs b/ntex/src/time/wheel.rs index 4a22eada..3454a715 100644 --- a/ntex/src/time/wheel.rs +++ b/ntex/src/time/wheel.rs @@ -648,7 +648,6 @@ mod tests { #[crate::rt_test] async fn test_timer() { - env_logger::init(); crate::rt::spawn(async { let s = interval(Millis(25)); loop {