From e292ba555369bd8f172301565d8145c49fab979d Mon Sep 17 00:00:00 2001 From: Brett Lawson Date: Tue, 17 Nov 2026 04:59:32 +0100 Subject: [PATCH] Home: make the preserved-mtime cache identity test wait for the change time to tick library_cache_identity_tracks_replacements_with_preserved_mtime rewrote a file with same-length content and its old mtime after a 2 ms sleep, so the cache key could only change through the inode change time. ctime advances at the kernel's coarse clock (one jiffy, 4 ms or more), so on CI both writes often landed in the same tick and the key stayed equal. The test now repeats the replacement (bounded at 2 s) until ctime moves, asserts that it moved and that the mtime was preserved, then asserts the cache path changed as before. Fixes #18333 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SdcgEtwSrdwZxqTQp5MfnU --- crates/ui-egui/src/home.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/home.rs b/crates/ui-egui/src/home.rs index 3674bcb5fa4..2f8367b6eb7 100644 --- a/crates/ui-egui/src/home.rs +++ b/crates/ui-egui/src/home.rs @@ -1267,9 +1267,22 @@ mod tests { std::fs::write(&path, b"old").unwrap(); let modified = std::fs::metadata(&path).unwrap().modified().unwrap(); let before = cache_path(path.to_str().unwrap()).unwrap(); - std::thread::sleep(std::time::Duration::from_millis(2)); - std::fs::write(&path, b"new").unwrap(); - std::fs::File::options().write(true).open(&path).unwrap().set_times(std::fs::FileTimes::new().set_modified(modified)).unwrap(); + // The change time ticks at the kernel's coarse clock (one jiffy, often 4 ms or more), so a + // replacement inside the same tick is indistinguishable by metadata. Replace until it ticks. + use std::os::unix::fs::MetadataExt; + let ctime = |p: &std::path::Path| std::fs::metadata(p).map(|m| (m.ctime(), m.ctime_nsec())).unwrap(); + let first = ctime(&path); + let deadline = std::time::Instant::now() + std::time::Duration::from_secs(2); + loop { + std::thread::sleep(std::time::Duration::from_millis(1)); + std::fs::write(&path, b"new").unwrap(); + std::fs::File::options().write(true).open(&path).unwrap().set_times(std::fs::FileTimes::new().set_modified(modified)).unwrap(); + if ctime(&path) != first || std::time::Instant::now() > deadline { + break; + } + } + assert_ne!(ctime(&path), first, "the change time never moved"); + assert_eq!(std::fs::metadata(&path).unwrap().modified().unwrap(), modified); assert_ne!(cache_path(path.to_str().unwrap()).unwrap(), before); }