test(core): serialize screen-file test with the TMPDIR-mutating test
screen_file_contents_and_write occasionally failed with NotFound when run in parallel with screen_temp_file_keeps_non_utf8_path_bytes: that test sets TMPDIR to a short-lived directory via temp_env, and std::env::temp_dir() evaluated outside temp_env's lock could resolve into it. The temp-file section now runs under temp_env's lock with TMPDIR unset. 25 consecutive runs of the core lib tests pass.
This commit is contained in:
1 parent
af094276f8
commit
daf5080453
1 file changed
+14
-4
@@ -1286,10 +1286,19 @@ mod tests {
|
|||||||
.is_none()
|
.is_none()
|
||||||
);
|
);
|
||||||
|
|
||||||
let path =
|
// Another test in this binary changes TMPDIR via temp_env, so the
|
||||||
write_screen_temp_file(&s, WriteScreenLoc::Screen, WriteScreenFormat::Plain).unwrap();
|
// whole temp-file section runs under temp_env's lock with TMPDIR
|
||||||
|
// unset (std::env::temp_dir() then cannot point into that test's
|
||||||
|
// short-lived directory).
|
||||||
|
temp_env::with_var_unset("TMPDIR", || {
|
||||||
|
let own_tmp = std::env::temp_dir()
|
||||||
|
.join(format!("ghostty-screen-file-test-{}", std::process::id()));
|
||||||
|
std::fs::create_dir_all(&own_tmp).unwrap();
|
||||||
|
let path = temp_env::with_var("TMPDIR", Some(&own_tmp), || {
|
||||||
|
write_screen_temp_file(&s, WriteScreenLoc::Screen, WriteScreenFormat::Plain)
|
||||||
|
.unwrap()
|
||||||
|
});
|
||||||
assert!(path.ends_with("screen.txt"));
|
assert!(path.ends_with("screen.txt"));
|
||||||
let path = path.to_string_lossy().into_owned(); // test-only: ASCII temp path
|
|
||||||
let read = std::fs::read_to_string(&path).unwrap();
|
let read = std::fs::read_to_string(&path).unwrap();
|
||||||
assert_eq!(read, s);
|
assert_eq!(read, s);
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
@@ -1299,7 +1308,8 @@ mod tests {
|
|||||||
);
|
);
|
||||||
assert_eq!(mode & 0o777, 0o600);
|
assert_eq!(mode & 0o777, 0o600);
|
||||||
}
|
}
|
||||||
let _ = std::fs::remove_dir_all(std::path::Path::new(&path).parent().unwrap());
|
let _ = std::fs::remove_dir_all(&own_tmp);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
|
|||||||
Reference in new issue
Block a user