From fb1fb6c903fca2b68871706b873f3f548148b4b4 Mon Sep 17 00:00:00 2001 From: k-nasa Date: Thu, 28 Nov 2019 22:53:24 +0900 Subject: [PATCH] test: Test the delay time --- src/stream/stream/mod.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/stream/stream/mod.rs b/src/stream/stream/mod.rs index cab0b39b..4fefbad5 100644 --- a/src/stream/stream/mod.rs +++ b/src/stream/stream/mod.rs @@ -585,14 +585,24 @@ extension_trait! { # use async_std::prelude::*; use async_std::stream; - use std::time::Duration; + use std::time::{Duration, Instant}; + let start = Instant::now(); let mut s = stream::from_iter(vec![0u8, 1, 2]).delay(Duration::from_millis(200)); assert_eq!(s.next().await, Some(0)); + // The first time will take more than 200ms due to delay. + assert!(start.elapsed().as_millis() >= 200); + assert_eq!(s.next().await, Some(1)); + // There will be no delay after the first time. + assert!(start.elapsed().as_millis() <= 210); + assert_eq!(s.next().await, Some(2)); + assert!(start.elapsed().as_millis() <= 210); + assert_eq!(s.next().await, None); + assert!(start.elapsed().as_millis() <= 210); # # }) } ```