Skip to content

Commit 091d994

Browse files
authored
Merge pull request #1899 from EliahKagan/run-ci/granularity
Improve filesystem timestamp granularity check
2 parents 316f113 + a5c58dd commit 091d994

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gix-fs/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ serde = { version = "1.0.114", optional = true, default-features = false, featur
2727
fastrand = { version = "2.1.0", default-features = false, features = ["std"] }
2828

2929
[dev-dependencies]
30-
tempfile = "3.5.0"
3130
crossbeam-channel = "0.5.0"
31+
is_ci = "1.1.1"
32+
tempfile = "3.5.0"

gix-fs/tests/fs/snapshot.rs

+23-12
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::path::Path;
44
#[test]
55
fn journey() -> Result<(), Box<dyn std::error::Error>> {
66
let tmp = tempfile::tempdir().unwrap();
7-
if !has_nanosecond_times(tmp.path())? {
7+
if !has_granular_times(tmp.path())? {
88
return Ok(());
99
}
1010

@@ -41,17 +41,28 @@ fn journey() -> Result<(), Box<dyn std::error::Error>> {
4141
Ok(())
4242
}
4343

44-
fn has_nanosecond_times(root: &Path) -> std::io::Result<bool> {
45-
let test_file = root.join("nanosecond-test");
44+
fn has_granular_times(root: &Path) -> std::io::Result<bool> {
45+
let n = 50;
4646

47-
std::fs::write(&test_file, "a")?;
48-
let first_time = test_file.metadata()?.modified()?;
49-
50-
std::fs::write(&test_file, "b")?;
51-
let second_time = test_file.metadata()?.modified()?;
47+
let paths = (0..n).map(|i| root.join(format!("{i:03}")));
48+
for (index, path) in paths.clone().enumerate() {
49+
std::fs::write(&path, index.to_string().as_bytes())?;
50+
}
51+
let mut times = Vec::new();
52+
for path in paths {
53+
times.push(path.symlink_metadata()?.modified()?);
54+
}
55+
times.sort();
56+
times.dedup();
5257

53-
Ok(second_time.duration_since(first_time).is_ok_and(|d|
54-
// This can be falsely false if a filesystem would be ridiculously fast,
55-
// which means a test won't run even though it could. But that's OK, and unlikely.
56-
d.subsec_nanos() != 0))
58+
// This could be wrongly false if a filesystem has very precise timings yet is ridiculously
59+
// fast. Then the `journey` test wouldn't run, though it could. But that's OK, and unlikely.
60+
if cfg!(target_os = "macos") && is_ci::cached() {
61+
assert_eq!(
62+
times.len(),
63+
n,
64+
"should have very granular timestamps at least on macOS on CI"
65+
);
66+
}
67+
Ok(times.len() == n)
5768
}

0 commit comments

Comments
 (0)