From 9371fea6e6f31a3c1ab23ae7be48120130c31533 Mon Sep 17 00:00:00 2001 From: Mattia Pitossi Date: Sat, 11 Apr 2026 14:31:53 +0000 Subject: [PATCH] fix spurious test failure in `metadata_access_times` * remove time assertion on SystemTime * skip test only if when a time change occurs --- library/std/src/fs/tests.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/library/std/src/fs/tests.rs b/library/std/src/fs/tests.rs index 42f3ccc340b27..b4cfbe4ff5f15 100644 --- a/library/std/src/fs/tests.rs +++ b/library/std/src/fs/tests.rs @@ -1731,6 +1731,8 @@ fn create_dir_all_with_junctions() { #[test] fn metadata_access_times() { + let start_time = SystemTime::now(); + let tmpdir = tmpdir(); let b = tmpdir.join("b"); @@ -1751,7 +1753,14 @@ fn metadata_access_times() { if cfg!(target_os = "linux") { // Not always available match (a.created(), b.created()) { - (Ok(t1), Ok(t2)) => assert!(t1 <= t2), + // It could be that, when the system clock goes backwards (e.g., due time change) + // b, that gets created after a, has a greater creation date than a. + // When such rare case occurs we skip the test, since the test to check that b + // should be created after a would fail. + (Ok(t1), Ok(t2)) => match start_time.elapsed() { + Ok(_) => assert!(t1 <= t2), + Err(_) => {} + }, (Err(e1), Err(e2)) if e1.kind() == ErrorKind::Uncategorized && e2.kind() == ErrorKind::Uncategorized