Test. More comment (#7251)
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
3ae52dacfc
commit
9ff1dfe019
@ -1483,25 +1483,6 @@ mod tests {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn test_tokio_time_interval() {
|
|
||||||
let mut timer = interval_maker();
|
|
||||||
let mut times = Vec::new();
|
|
||||||
sleep(Duration::from_secs(3)).await;
|
|
||||||
loop {
|
|
||||||
tokio::select! {
|
|
||||||
_ = timer.tick() => {
|
|
||||||
times.push(now_time_string());
|
|
||||||
if times.len() == 5 {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let times2: HashSet<String> = HashSet::from_iter(times.clone());
|
|
||||||
assert_eq!(times.len(), times2.len() + 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ThrottledInterval tick at the same time as tokio interval, if no sleeps
|
// ThrottledInterval tick at the same time as tokio interval, if no sleeps
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@ -1532,6 +1513,25 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_tokio_time_interval_sleep() {
|
||||||
|
let mut timer = interval_maker();
|
||||||
|
let mut times = Vec::new();
|
||||||
|
sleep(Duration::from_secs(3)).await;
|
||||||
|
loop {
|
||||||
|
tokio::select! {
|
||||||
|
_ = timer.tick() => {
|
||||||
|
times.push(now_time_string());
|
||||||
|
if times.len() == 5 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let times2: HashSet<String> = HashSet::from_iter(times.clone());
|
||||||
|
assert_eq!(times.len(), times2.len() + 3);
|
||||||
|
}
|
||||||
|
|
||||||
// ThrottledInterval tick less times than tokio interval, if there're sleeps
|
// ThrottledInterval tick less times than tokio interval, if there're sleeps
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@ -1553,6 +1553,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
// No mutliple ticks in the `interval` time.
|
// No mutliple ticks in the `interval` time.
|
||||||
// Values in "times" are unique and are less than normal tokio interval.
|
// Values in "times" are unique and are less than normal tokio interval.
|
||||||
|
// See previous test (test_tokio_time_interval_sleep) for comparison.
|
||||||
let times2: HashSet<String> = HashSet::from_iter(times.clone());
|
let times2: HashSet<String> = HashSet::from_iter(times.clone());
|
||||||
assert_eq!(times.len(), times2.len());
|
assert_eq!(times.len(), times2.len());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user