Skip to content

Commit 5990fd4

Browse files
committed
fix: prevent orphan processes in exec timeout test
Use trap + background sleep pattern so the child process handles SIGTERM cleanly instead of leaving a sleep 60 orphan that causes GitHub Actions to fail during post-job cleanup.
1 parent 5e2b2a3 commit 5990fd4

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

crates/sandchest-agent/src/exec.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,15 +418,16 @@ mod tests {
418418
#[tokio::test]
419419
async fn exec_timeout_kills_process() {
420420
let mut req = make_request();
421-
req.shell_cmd = "sleep 60".into();
421+
// Use trap to prevent orphan processes on CI (GHA fails on orphan cleanup)
422+
req.shell_cmd = "trap 'exit 143' TERM; sleep 10 & wait".into();
422423
req.timeout_seconds = 1;
423424

424425
let start = Instant::now();
425426
let events = collect_exec_events(req).await;
426427
let elapsed = start.elapsed();
427428

428-
// Should complete well before the 60s sleep
429-
assert!(elapsed < Duration::from_secs(10));
429+
// Should complete well before the 10s sleep
430+
assert!(elapsed < Duration::from_secs(5));
430431

431432
let exit_event = events
432433
.iter()
@@ -443,6 +444,9 @@ mod tests {
443444
"timed-out process should exit with -1 or 143, got {}",
444445
exit_event.exit_code
445446
);
447+
448+
// Brief wait to ensure process is fully reaped (prevents GHA orphan cleanup errors)
449+
tokio::time::sleep(Duration::from_millis(100)).await;
446450
}
447451

448452
#[tokio::test]

0 commit comments

Comments
 (0)