Skip to content

Commit 144c898

Browse files
committed
test(process): Stabilize Windows tree fixtures
Windows CI timed out waiting for descendant PIDs in both process-tree cleanup tests, although the original fixtures passed locally. - Replace PowerShell and ping fixtures with explicit parent and leaf roles in the existing test executable. - Publish readiness from the running leaf itself and keep subprocesses hidden through the shared process command helper. - Preserve parent-exit coverage, cleanup assertions, and timeout bounds without changing production process-tree behavior. This removes external shell startup and launch dependencies from the fixture without claiming a confirmed cause for the original CI timeout. Validation: process-tree tests passed ten consecutive Windows runs; all five process-runtime integration contracts also passed.
1 parent d6fa7a7 commit 144c898

1 file changed

Lines changed: 49 additions & 16 deletions

File tree

‎src/crates/services/services-core/src/process_tree.rs‎

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -473,30 +473,63 @@ mod tests {
473473

474474
#[cfg(windows)]
475475
fn descendant_fixture(pid_file: &Path) -> Command {
476-
let script = r#"$child = Start-Process -FilePath "$env:SystemRoot\System32\ping.exe" -ArgumentList '-t','127.0.0.1' -WindowStyle Hidden -PassThru; [IO.File]::WriteAllText($env:OPENBITFUN_DESCENDANT_PID_FILE, [string]$child.Id); while ($true) { Start-Sleep -Seconds 60 }"#;
477-
let mut command = Command::new("powershell.exe");
478-
command
479-
.arg("-NoProfile")
480-
.arg("-NonInteractive")
481-
.arg("-Command")
482-
.arg(script)
483-
.env("OPENBITFUN_DESCENDANT_PID_FILE", pid_file);
484-
command
476+
Command::from(windows_fixture_command(pid_file, "parent"))
485477
}
486478

487479
#[cfg(windows)]
488480
fn orphaned_descendant_fixture(pid_file: &Path) -> Command {
489-
let script = r#"$child = Start-Process -FilePath "$env:SystemRoot\System32\ping.exe" -ArgumentList '-t','127.0.0.1' -WindowStyle Hidden -PassThru; [IO.File]::WriteAllText($env:OPENBITFUN_DESCENDANT_PID_FILE, [string]$child.Id)"#;
490-
let mut command = Command::new("powershell.exe");
481+
Command::from(windows_fixture_command(pid_file, "orphan-parent"))
482+
}
483+
484+
#[cfg(windows)]
485+
fn windows_fixture_command(pid_file: &Path, role: &str) -> std::process::Command {
486+
// Reuse the test binary so readiness does not depend on PowerShell
487+
// startup, Start-Process behavior, or an external ping executable.
488+
let mut command = crate::process_manager::create_command(
489+
std::env::current_exe().expect("locate process-tree test executable"),
490+
);
491491
command
492-
.arg("-NoProfile")
493-
.arg("-NonInteractive")
494-
.arg("-Command")
495-
.arg(script)
496-
.env("OPENBITFUN_DESCENDANT_PID_FILE", pid_file);
492+
.args([
493+
"--exact",
494+
"process_tree::tests::windows_fixture_process",
495+
"--nocapture",
496+
])
497+
.env("OPENBITFUN_PROCESS_TREE_FIXTURE_ROLE", role)
498+
.env("OPENBITFUN_DESCENDANT_PID_FILE", pid_file)
499+
.stdin(Stdio::null())
500+
.stdout(Stdio::null())
501+
.stderr(Stdio::inherit());
497502
command
498503
}
499504

505+
#[cfg(windows)]
506+
#[test]
507+
fn windows_fixture_process() {
508+
let Ok(role) = std::env::var("OPENBITFUN_PROCESS_TREE_FIXTURE_ROLE") else {
509+
return;
510+
};
511+
let pid_file =
512+
std::env::var_os("OPENBITFUN_DESCENDANT_PID_FILE").expect("fixture PID file path");
513+
match role.as_str() {
514+
"parent" | "orphan-parent" => {
515+
let _child = windows_fixture_command(Path::new(&pid_file), "leaf")
516+
.spawn()
517+
.expect("spawn fixture descendant");
518+
if role == "orphan-parent" {
519+
return;
520+
}
521+
}
522+
"leaf" => {
523+
std::fs::write(&pid_file, std::process::id().to_string())
524+
.expect("publish fixture descendant PID");
525+
}
526+
_ => panic!("unknown process-tree fixture role: {role}"),
527+
}
528+
loop {
529+
std::thread::sleep(Duration::from_secs(60));
530+
}
531+
}
532+
500533
#[cfg(unix)]
501534
fn descendant_fixture(pid_file: &Path) -> Command {
502535
let mut command = Command::new("sh");

0 commit comments

Comments
 (0)