Tests: the link-watch and place tests wait for the link scan instead of sleeping

The link-watch worker now signals a condition variable when it ends,
whether it stored its stamps or unwound, and Session::wait_link_scan
blocks until then. The place tests' idle helper waits on it once per look
in place of a 5 ms sleep under a 20 s wall-clock bound, and the engine's
link-watch and link-path tests wait on it in place of spinning under a
10 s bound. The link-watch tests date a rewritten file 2 s after the one
it replaces instead of sleeping 30 ms before writing it.
This commit is contained in:
dotCooCoo
2026-11-05 02:23:48 +07:00
committed by bflatastic
parent 08bd77054d
commit a5157654f4
4 changed files with 49 additions and 25 deletions
+2 -5
View File
@@ -77,11 +77,8 @@ fn linked_files_on_other_computers_are_never_read() {
}
s.execute("links.updateChanged", &json!({})).unwrap();
s.start_link_scan();
let t0 = std::time::Instant::now();
while s.poll_link_scan().is_none() {
assert!(t0.elapsed().as_secs() < 10, "the look never finished");
std::thread::yield_now();
}
s.wait_link_scan();
assert!(s.poll_link_scan().is_some(), "no look ran");
});
assert_eq!(far_reads(&seen), Vec::<&String>::new());
// The watch kept no stamp of them (`//tmp/…` would have one had it been looked at).
+7 -10
View File
@@ -6,10 +6,13 @@ use serde_json::{Value, json};
use crate::tests_links::{BLUE, Folder, RED, centre_colour, place, png, session};
use crate::*;
/// Write `bytes` to `path` so its modification time moves even on coarse file systems.
/// Write `bytes` to `path`, dated 2 s after the file it replaces so its modification time moves
/// even on coarse file systems.
fn save(path: &str, bytes: &[u8]) {
std::thread::sleep(std::time::Duration::from_millis(30));
let stamp = std::fs::metadata(path).unwrap().modified().unwrap();
std::fs::write(path, bytes).unwrap();
let later = std::fs::FileTimes::new().set_modified(stamp + std::time::Duration::from_secs(2));
std::fs::OpenOptions::new().write(true).open(path).unwrap().set_times(later).unwrap();
}
fn colour(s: &Session) -> [u8; 3] {
@@ -19,14 +22,8 @@ fn colour(s: &Session) -> [u8; 3] {
/// One background look, waited for.
fn look(s: &mut Session) -> Value {
s.start_link_scan();
let t0 = std::time::Instant::now();
loop {
if let Some(r) = s.poll_link_scan() {
return r.unwrap();
}
assert!(t0.elapsed().as_secs() < 10, "the look never finished");
std::thread::yield_now();
}
s.wait_link_scan();
s.poll_link_scan().expect("a look ran").unwrap()
}
#[test]