Wait for SIGKILLed job processes to exit before checking them
Browse files at this commit74e2f807ddf2cf0d524c042998726f9cd41101b2Parent: b495552- test
- wait for SIGKILLed job processes to exit before checking them
1 changed file +17 -1
crates/forge-runner/tests/integration/builtin.rsmodified+17 -1
| @@ -253,6 +253,19 @@ fn process_gone(pid: u32) -> bool { | ||
| 253 | 253 | } |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | +/// Waits up to five seconds for `pid` to exit. A SIGKILLed process leaves its cgroup before it | |
| 257 | +/// finishes exiting, so a single check right after the cgroup is gone can still see it running. | |
| 258 | +async fn wait_gone(pid: u32) -> bool { | |
| 259 | + let deadline = Instant::now() + Duration::from_secs(5); | |
| 260 | + while !process_gone(pid) { | |
| 261 | + if Instant::now() >= deadline { | |
| 262 | + return false; | |
| 263 | + } | |
| 264 | + tokio::time::sleep(Duration::from_millis(20)).await; | |
| 265 | + } | |
| 266 | + true | |
| 267 | +} | |
| 268 | + | |
| 256 | 269 | /// The helper is SIGKILLed while its job is still running, so it cannot tear the container down. |
| 257 | 270 | /// The executor must then kill the job's processes, remove its cgroup, and remove its job dir. |
| 258 | 271 | #[tokio::test] |
| @@ -298,7 +311,10 @@ async fn sigkilled_helper_leaves_no_process_behind() { | ||
| 298 | 311 | cgroup.display() |
| 299 | 312 | ); |
| 300 | 313 | for pid in &procs { |
| 301 | - assert!(process_gone(*pid), "job process {pid} survived the helper"); | |
| 314 | + assert!( | |
| 315 | + wait_gone(*pid).await, | |
| 316 | + "job process {pid} survived the helper" | |
| 317 | + ); | |
| 302 | 318 | } |
| 303 | 319 | assert!(!dir.path().join("jobs/job_01").exists(), "job dir was kept"); |
| 304 | 320 | } |