diff --git a/crates/forge-runner/tests/integration/builtin.rs b/crates/forge-runner/tests/integration/builtin.rs index b569211..5802d1b 100644 --- a/crates/forge-runner/tests/integration/builtin.rs +++ b/crates/forge-runner/tests/integration/builtin.rs @@ -253,6 +253,19 @@ fn process_gone(pid: u32) -> bool { } } +/// Waits up to five seconds for `pid` to exit. A SIGKILLed process leaves its cgroup before it +/// finishes exiting, so a single check right after the cgroup is gone can still see it running. +async fn wait_gone(pid: u32) -> bool { + let deadline = Instant::now() + Duration::from_secs(5); + while !process_gone(pid) { + if Instant::now() >= deadline { + return false; + } + tokio::time::sleep(Duration::from_millis(20)).await; + } + true +} + /// The helper is SIGKILLed while its job is still running, so it cannot tear the container down. /// The executor must then kill the job's processes, remove its cgroup, and remove its job dir. #[tokio::test] @@ -298,7 +311,10 @@ async fn sigkilled_helper_leaves_no_process_behind() { cgroup.display() ); for pid in &procs { - assert!(process_gone(*pid), "job process {pid} survived the helper"); + assert!( + wait_gone(*pid).await, + "job process {pid} survived the helper" + ); } assert!(!dir.path().join("jobs/job_01").exists(), "job dir was kept"); }