forked from mirror/async-std
test: Test the delay time
This commit is contained in:
parent
da965e9ba4
commit
fb1fb6c903
1 changed files with 11 additions and 1 deletions
|
@ -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);
|
||||
#
|
||||
# }) }
|
||||
```
|
||||
|
|
Loading…
Reference in a new issue