Add a failing test for detecting a file move

This commit is contained in:
Nathan Sobo 2021-04-12 19:34:43 -06:00
parent 41f50cdb61
commit bc34ff54fe
2 changed files with 74 additions and 0 deletions

View file

@ -2,6 +2,7 @@ use rand::Rng;
use std::{
collections::BTreeMap,
path::{Path, PathBuf},
time::{Duration, Instant},
};
use tempdir::TempDir;
@ -136,3 +137,18 @@ fn write_tree(path: &Path, tree: serde_json::Value) {
panic!("You must pass a JSON object to this helper")
}
}
pub async fn assert_condition(poll_interval: u64, timeout: u64, mut f: impl FnMut() -> bool) {
let poll_interval = Duration::from_millis(poll_interval);
let timeout = Duration::from_millis(timeout);
let start = Instant::now();
loop {
if f() {
return;
} else if Instant::now().duration_since(start) < timeout {
smol::Timer::after(poll_interval).await;
} else {
panic!("timed out waiting on condition");
}
}
}