From 7cace373c06e95b7a400d83f488362262f72e673 Mon Sep 17 00:00:00 2001 From: mavrick Date: Wed, 2 Dec 2026 10:57:29 -0600 Subject: [PATCH 1/2] test(data): a rewritten shapefile waits for its change time to move The change time moves with the system's coarse clock, so a write in the tick the file was opened in left it as it was and the test failed about half the time. The test writes again until the change time has moved. --- crates/data/src/source/shp/tests.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/crates/data/src/source/shp/tests.rs b/crates/data/src/source/shp/tests.rs index bf3556a68f..0ca27e898d 100644 --- a/crates/data/src/source/shp/tests.rs +++ b/crates/data/src/source/shp/tests.rs @@ -971,12 +971,30 @@ 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); + for _ in 0..1_000_000 { + std::fs::write(&dbf, &bytes).unwrap(); + std::fs::File::options().write(true).open(&dbf).unwrap().set_modified(modified).unwrap(); + #[cfg(unix)] + if changed_at(&dbf) != opened_at { + break; + } + #[cfg(not(unix))] + break; + } #[cfg(unix)] assert!(!s.same_as_opened().unwrap(), "written again at the same size and time"); let s = ShpSource::open_path(&path, "pts").unwrap(); From 041f2624476e22add4796cda2aae99e02f2d74e4 Mon Sep 17 00:00:00 2001 From: mavrick Date: Wed, 2 Dec 2026 12:53:36 -0600 Subject: [PATCH 2/2] test(data): the shapefile rewrite loop runs on Unix only, for at most two seconds On other systems the file is written once (a loop that always broke first time is clippy's never_loop). The loop is bounded by time, not a million rewrites. --- crates/data/src/source/shp/tests.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/data/src/source/shp/tests.rs b/crates/data/src/source/shp/tests.rs index 0ca27e898d..826ac1c9bc 100644 --- a/crates/data/src/source/shp/tests.rs +++ b/crates/data/src/source/shp/tests.rs @@ -985,15 +985,17 @@ fn a_shapefile_says_whether_it_is_as_it_was_opened() { }; #[cfg(unix)] let opened_at = changed_at(&dbf); - for _ in 0..1_000_000 { + let rewrite = || { std::fs::write(&dbf, &bytes).unwrap(); std::fs::File::options().write(true).open(&dbf).unwrap().set_modified(modified).unwrap(); - #[cfg(unix)] - if changed_at(&dbf) != opened_at { - break; + }; + 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(not(unix))] - break; } #[cfg(unix)] assert!(!s.same_as_opened().unwrap(), "written again at the same size and time");