forge
Explore
Log in

Don't you dare go Hollow

Forge-runner signal tests stop interfering inside the merged test binary

Browse files at this commit

20b2c509829900e9b94ec7d1cd79503b36911cdcAhmet Kaan GümüşParent: 38d0181
  • fix
    • forge-runner signal tests stop interfering inside the merged test binary
Show full message
🐛 fix: forge-runner signal tests stop interfering inside the merged test binary

Root cause: sigkilled_helper_leaves_no_process_behind found its helper by scanning every
__sandbox child of the test process. The sandbox tests spawn their helpers from that same
process, all with job id job_01. Under plain cargo test (threads in one process) the killer
SIGKILLed sigterm_kills_the_container_and_the_helper_exits' helper. That helper's sleep 60 job
survived, held the stdout pipe, and wait_with_output blocked about 60 s, tripping the 20 s
check. The sigkill test's own helper was never killed, so its sleep 300 ran to Success, which
made the run take about 300 s.

Fix: the sigkill test uses its own job id (job_sigkill), and the helper search matches only
that job's cgroup name. No assertions changed and no tests removed.
crates/forge-runner/tests/integration/builtin.rsmodified+12 -8
@@ -197,8 +197,8 @@ async fn sandbox_setup_failure_is_an_error_with_the_reason() {
197 );197 );
198 }198 }
199 199
200-/// The builtin tests run in one process. Each takes this lock, so the helper-finding test below200+/// The builtin tests run in one process. Each takes this lock, so their jobs do not run at once.
201-/// never sees another test's helper as its own child.201+/// The helper-finding test below matches its own job cgroup, not any helper child of the process.
202 static SERIAL: tokio::sync::Mutex<()> = tokio::sync::Mutex::const_new(());202 static SERIAL: tokio::sync::Mutex<()> = tokio::sync::Mutex::const_new(());
203 203
204 async fn serial() -> tokio::sync::MutexGuard<'static, ()> {204 async fn serial() -> tokio::sync::MutexGuard<'static, ()> {
@@ -226,9 +226,9 @@ fn helper_children() -> Vec<u32> {
226 .collect()226 .collect()
227 }227 }
228 228
229-/// The job cgroup directory of the helper with pid `helper`, for job `job_01`.229+/// The job cgroup directory of the helper with pid `helper`, for job `job_id`.
230-fn job_cgroup_dir(helper: u32) -> PathBuf {230+fn job_cgroup_dir(job_id: &str, helper: u32) -> PathBuf {
231- let rel = job_cgroup_path("job_01", helper).expect("job cgroup path");231+ let rel = job_cgroup_path(job_id, helper).expect("job cgroup path");
232 Path::new("/sys/fs/cgroup").join(rel.strip_prefix("/").unwrap_or(&rel))232 Path::new("/sys/fs/cgroup").join(rel.strip_prefix("/").unwrap_or(&rel))
233 }233 }
234 234
@@ -278,14 +278,18 @@ async fn sigkilled_helper_leaves_no_process_behind() {
278 let (exec, workspace) = executor(dir.path());278 let (exec, workspace) = executor(dir.path());
279 // `trap '' TERM` makes the job ignore SIGTERM. Only the helper's SIGKILL path can stop it.279 // `trap '' TERM` makes the job ignore SIGTERM. Only the helper's SIGKILL path can stop it.
280 let run = "trap '' TERM; sleep 300";280 let run = "trap '' TERM; sleep 300";
281- let job_spec = job(run);281+ // A job id of its own. `helper_children` also finds the helpers of the other tests in this
282+ // process, and only this job's cgroup name identifies this test's helper.
283+ let job_id = "job_sigkill";
284+ let mut job_spec = job(run);
285+ job_spec.job_id = job_id.to_owned();
282 286
283 let killer = async {287 let killer = async {
284 let deadline = Instant::now() + Duration::from_secs(30);288 let deadline = Instant::now() + Duration::from_secs(30);
285 let (helper, cgroup, procs) = loop {289 let (helper, cgroup, procs) = loop {
286 assert!(Instant::now() < deadline, "the job never started");290 assert!(Instant::now() < deadline, "the job never started");
287 let found = helper_children().into_iter().find_map(|pid| {291 let found = helper_children().into_iter().find_map(|pid| {
288- let cgroup = job_cgroup_dir(pid);292+ let cgroup = job_cgroup_dir(job_id, pid);
289 let procs = procs_in(&cgroup);293 let procs = procs_in(&cgroup);
290 (!procs.is_empty()).then_some((pid, cgroup, procs))294 (!procs.is_empty()).then_some((pid, cgroup, procs))
291 });295 });
@@ -316,5 +320,5 @@ async fn sigkilled_helper_leaves_no_process_behind() {
316 "job process {pid} survived the helper"320 "job process {pid} survived the helper"
317 );321 );
318 }322 }
319- assert!(!dir.path().join("jobs/job_01").exists(), "job dir was kept");323+ assert!(!dir.path().join("jobs").join(job_id).exists(), "job dir was kept");
320 }324 }