Skip to content

Commit f61050f

Browse files
authored
Merge pull request #34 from lucab/ups/tests-cached-time
tests: fix race condition in timestamp checking
2 parents 08b9353 + 3e7af9a commit f61050f

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/lib.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -908,21 +908,16 @@ mod tests {
908908
let td = tempfile::tempdir().unwrap();
909909
let d = openat::Dir::open(td.path()).unwrap();
910910
d.ensure_dir("foo", 0o755).unwrap();
911-
d.syncfs().unwrap();
912911
let before = d.metadata("foo").unwrap();
912+
// File timestamps can not be updated faster than kernel ticking granularity,
913+
// so this artificially sleeps through several timer interrupts.
914+
std::thread::sleep(std::time::Duration::from_millis(100));
913915

914916
d.update_timestamps("foo").unwrap();
915-
d.syncfs().unwrap();
916917
let after = d.metadata("foo").unwrap();
917-
918-
assert!(
919-
before.stat().st_atime != after.stat().st_atime
920-
|| before.stat().st_atime_nsec != after.stat().st_atime_nsec
921-
);
922-
assert!(
923-
before.stat().st_mtime != after.stat().st_mtime
924-
|| before.stat().st_mtime_nsec != after.stat().st_mtime_nsec
925-
);
918+
if before.stat().st_mtime == after.stat().st_mtime {
919+
assert_ne!(before.stat().st_mtime_nsec, after.stat().st_mtime_nsec);
920+
}
926921
}
927922

928923
#[test]

0 commit comments

Comments
 (0)