diff --git a/crates/data/src/source/shp/tests.rs b/crates/data/src/source/shp/tests.rs index bf3556a68f..826ac1c9bc 100644 --- a/crates/data/src/source/shp/tests.rs +++ b/crates/data/src/source/shp/tests.rs @@ -971,12 +971,32 @@ fn a_shapefile_says_whether_it_is_as_it_was_opened() { cache::with_index_dir(tmp.path().join("cache"), || { let s = ShpSource::open_path(&path, "pts").unwrap(); assert!(s.same_as_opened().unwrap(), "as opened"); - // The same size, its time set back: the change time still moves. + // The same size, its time set back: the change time still moves. It moves with the + // system's coarse clock, so a write in the tick the file was opened in leaves it as it + // was: written again until it has moved (a few milliseconds). let dbf = path.with_extension("dbf"); let modified = std::fs::metadata(&dbf).unwrap().modified().unwrap(); let bytes = std::fs::read(&dbf).unwrap(); - std::fs::write(&dbf, &bytes).unwrap(); - std::fs::File::options().write(true).open(&dbf).unwrap().set_modified(modified).unwrap(); + #[cfg(unix)] + let changed_at = |p: &std::path::Path| { + use std::os::unix::fs::MetadataExt; + let m = std::fs::metadata(p).unwrap(); + (m.ctime(), m.ctime_nsec()) + }; + #[cfg(unix)] + let opened_at = changed_at(&dbf); + let rewrite = || { + std::fs::write(&dbf, &bytes).unwrap(); + std::fs::File::options().write(true).open(&dbf).unwrap().set_modified(modified).unwrap(); + }; + rewrite(); + #[cfg(unix)] + { + let give_up = std::time::Instant::now() + std::time::Duration::from_secs(2); // test-wait: the change time moves with the system's clock tick, which no signal announces; two seconds cover a file system that keeps whole seconds. + while changed_at(&dbf) == opened_at && std::time::Instant::now() < give_up { + rewrite(); + } + } #[cfg(unix)] assert!(!s.same_as_opened().unwrap(), "written again at the same size and time"); let s = ShpSource::open_path(&path, "pts").unwrap();