test(ssh-config): let the second write to an included file be seen as one

`an_alias_added_to_an_included_file_is_seen_without_touching_the_root`
failed on every Windows run of this branch and had passed on main by a
margin the branch happened to spend elsewhere.

The cache keys on mtime, the test writes `conf.d/work` twice back to
back, and Windows stamps files from a clock that ticks about every 15ms —
so both writes can land on one mtime, and the cache is then correct to say
nothing changed. Nothing in the product depends on resolving edits that
close: the poll behind this runs at 4Hz and a real edit arrives at human
speed. It is the test that is too fast, so the second write now says when
it happened rather than sleeping out the tick.
This commit is contained in:
l0ng-ai
2026-08-12 00:52:01 +08:00
parent 1c8a472354
commit b5b8d46f8a
+16
View File
@@ -1423,6 +1423,7 @@ mod tests {
);
std::fs::write(ssh.join("conf.d/work"), "Host work\n").unwrap();
edited_just_now(&ssh.join("conf.d/work"));
assert!(
cache.resolves(&cfg, &root, "work"),
"an alias put back in an included file is found again, \
@@ -1430,6 +1431,21 @@ mod tests {
);
}
/// Make a write that has just happened look like one, on a filesystem
/// whose clock is coarser than this test is fast.
///
/// Windows stamps files from a clock that ticks about every 15ms, so two
/// writes as close together as the ones above can share an mtime — and a
/// cache keyed on mtime is then right to say nothing changed. A real edit
/// arrives at human speed, and the poll behind this cache runs at 4Hz, so
/// the collision is an artefact of the test rather than something a user
/// can reach. Stated by hand instead of slept out.
fn edited_just_now(path: &Path) {
let f = std::fs::File::options().write(true).open(path).unwrap();
let ahead = std::time::SystemTime::now() + std::time::Duration::from_secs(1);
f.set_modified(ahead).unwrap();
}
fn temp_root(name: &str) -> PathBuf {
let dir = std::env::temp_dir().join(format!(
"tty7-ssh-config-test-{name}-{}",