Forge-runner signal tests stop interfering inside the merged test binary
Browse files at this commit20b2c509829900e9b94ec7d1cd79503b36911cdcParent: 38d0181- fix
- forge-runner signal tests stop interfering inside the merged test binary
1 changed file +12 -8
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 below | 200 | +/// 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 | } |