mirror of
https://github.com/storytold/craft-anything.git
synced 2026-11-19 05:50:53 +01:00
Make watched descendant shutdown tests reliable and isolated
This commit is contained in:
1 parent
eddfaba0ce
commit
07671fe771
3 files changed
+39
-5
No files matched your search
@@ -1294,14 +1294,21 @@ mod launch_tests {
|
||||
assert!(l.ended().unwrap().after < Duration::from_secs(20));
|
||||
}
|
||||
|
||||
/// A descendant must leave its heartbeat unchanged once its watched launch has stopped.
|
||||
#[test]
|
||||
fn stopping_a_watched_program_stops_its_descendant() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let exe = std::env::current_exe().unwrap();
|
||||
let command = if cfg!(windows) {
|
||||
format!(r#"start "" /B "{}" --ignored --exact process::launch_tests::watched_descendant_stand_in & ping -n 30 127.0.0.1 > NUL"#, exe.display())
|
||||
format!(
|
||||
r#"set "CRAFT_ANYTHING_TEST_DESCENDANT=1" & start "" /B "{}" --ignored --exact process::launch_tests::watched_descendant_stand_in & ping -n 30 127.0.0.1 > NUL"#,
|
||||
exe.display()
|
||||
)
|
||||
} else {
|
||||
format!("{} --ignored --exact process::launch_tests::watched_descendant_stand_in & wait", shell_quote(&exe.to_string_lossy()))
|
||||
format!(
|
||||
"CRAFT_ANYTHING_TEST_DESCENDANT=1 {} --ignored --exact process::launch_tests::watched_descendant_stand_in & wait",
|
||||
shell_quote(&exe.to_string_lossy())
|
||||
)
|
||||
};
|
||||
let l = shell(&command).cwd(dir.path()).start_watched().unwrap();
|
||||
let started = dir.path().join("descendant-started");
|
||||
@@ -1312,15 +1319,19 @@ mod launch_tests {
|
||||
}
|
||||
assert!(started.exists(), "descendant never signalled that it started");
|
||||
assert!(heartbeat.exists(), "descendant never produced a heartbeat");
|
||||
let before_stop = std::fs::read(&heartbeat).unwrap();
|
||||
assert!(l.stop());
|
||||
let after_stop = std::fs::read(&heartbeat).unwrap();
|
||||
std::thread::sleep(Duration::from_millis(500));
|
||||
assert_eq!(std::fs::read(&heartbeat).unwrap(), before_stop, "descendant continued running after the watched program stopped");
|
||||
assert_eq!(std::fs::read(&heartbeat).unwrap(), after_stop, "descendant continued running after the watched program stopped");
|
||||
}
|
||||
|
||||
/// Emit liveness markers only when the parent test explicitly enables this child fixture.
|
||||
#[test]
|
||||
#[ignore = "stand-in invoked by stopping_a_watched_program_stops_its_descendant"]
|
||||
fn watched_descendant_stand_in() {
|
||||
if std::env::var_os("CRAFT_ANYTHING_TEST_DESCENDANT").as_deref() != Some(OsStr::new("1")) {
|
||||
return;
|
||||
}
|
||||
std::fs::write("descendant-started", b"ready").unwrap();
|
||||
for n in 0..100 {
|
||||
std::fs::write("descendant-heartbeat", n.to_string()).unwrap();
|
||||
@@ -1329,6 +1340,21 @@ mod launch_tests {
|
||||
std::fs::write("descendant-survived", b"yes").unwrap();
|
||||
}
|
||||
|
||||
/// An ignored-test invocation without the child guard must leave its working directory empty.
|
||||
#[test]
|
||||
fn a_direct_descendant_stand_in_run_writes_nothing() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let out = Process::new(std::env::current_exe().unwrap())
|
||||
.args(["--ignored", "--exact", "process::launch_tests::watched_descendant_stand_in"])
|
||||
.env_remove("CRAFT_ANYTHING_TEST_DESCENDANT")
|
||||
.cwd(dir.path())
|
||||
.run()
|
||||
.unwrap();
|
||||
assert!(out.success, "{}", out.stderr_text());
|
||||
assert_eq!(std::fs::read_dir(dir.path()).unwrap().count(), 0, "the unguarded stand-in wrote files");
|
||||
}
|
||||
|
||||
/// Quote one Unix shell argument, including embedded apostrophes.
|
||||
fn shell_quote(value: &str) -> String {
|
||||
format!("'{}'", value.replace('\'', "'\\''"))
|
||||
}
|
||||
|
||||
+4
-1
@@ -167,9 +167,12 @@ cheapest help we can give anyone, so nothing below should hold it up for long.
|
||||
|
||||
### R5.2 Keeping contributions moving
|
||||
Owner: maintainers · Status: in progress
|
||||
- [ ] Address PR #1030 review: take the heartbeat baseline after stopping, guard the descendant
|
||||
- [x] Address PR #1030 review: take the heartbeat baseline after stopping, guard the descendant
|
||||
stand-in against direct ignored-test runs, and document the test helpers
|
||||
— claimed: Codex, branch bugfix/r5.2-watched-launch-tests
|
||||
- [ ] `regression_preview_limits_connections_and_releases_listener` (platform) fails on macOS
|
||||
with `Invalid argument` in its socket fixture, also reported before PR #1030's review fixes.
|
||||
Investigate the fixture separately from the watched descendant shutdown test
|
||||
Review comes before new work while the queue is long, smallest and clean PRs first. A PR is merged
|
||||
only when it's green and a maintainer has fully reviewed it, code as well as wording.
|
||||
- [ ] Maintainers: protect `main` (PRs required, squash only); the only ruleset covers `release`
|
||||
|
||||
@@ -78,6 +78,11 @@ names (`git merge-base --is-ancestor <fix> <release tag>`), and check the messag
|
||||
|
||||
## Tests
|
||||
|
||||
**A heartbeat sampled before shutdown raced a successful stop.** A child could write between
|
||||
the baseline read and `stop()`, failing the descendant cleanup test even when cleanup worked.
|
||||
Sample after the stop returns, then check for further writes. Ignored child fixtures also need
|
||||
an explicit launch guard so running ignored tests directly cannot write in the working directory.
|
||||
|
||||
**An isolated PATH still assumed system utilities lived in `/bin`.** The remote setup fixture
|
||||
linked `mkdir`, `chmod` and `mv` there, so a host with utilities elsewhere got dangling links.
|
||||
Resolve fixture utilities on the host, make their paths absolute, then populate the private PATH.
|
||||
|
||||
Reference in new issue
Block a user