client/authority-discovery: Increase margins for interval test (#4297)

`interval_at_is_queuing_ticks` test shows to be flaky. This commit
increases the time margins while also reducing the amount of necessary
time ticks.
This commit is contained in:
Max Inden
2019-12-05 14:01:59 +01:00
committed by Gavin Wood
parent 7714bfca8e
commit e126ca9b2c
@@ -547,24 +547,26 @@ mod tests {
}
#[test]
fn interval_at_is_queuing_events() {
fn interval_at_is_queuing_ticks() {
let start = Instant::now();
let interval = interval_at(
std::time::Instant::now(),
std::time::Duration::from_millis(10),
start,
std::time::Duration::from_millis(100),
);
// Let's wait for 100ms, thus 10 elements should be queued up.
std::thread::sleep(Duration::from_millis(100));
// Let's wait for 200ms, thus 3 elements should be queued up (1st at 0ms, 2nd at 100ms, 3rd
// at 200ms).
std::thread::sleep(Duration::from_millis(200));
futures::executor::block_on(async {
interval.take(10).collect::<Vec<()>>().await;
interval.take(3).collect::<Vec<()>>().await;
});
// Make sure we did not just wait for yet another 100ms (10 elements).
// Make sure we did not wait for more than 300 ms, which would imply that `at_interval` is
// not queuing ticks.
assert!(
Instant::now().saturating_duration_since(start) < Duration::from_millis(150),
Instant::now().saturating_duration_since(start) < Duration::from_millis(300),
"Expect interval to /queue/ events when not polled for a while.",
);
}