runSubprocess re-execs the current test binary in a new process running only the named test. This isolates ForkReap's syscall.ForkExec and any process-directed signals (e.g. SIGINT) from the parent test binary, making these tests safe to run in CI and alongside other tests. Returns true inside the
(t *testing.T)
| 35 | // the real test logic). Returns false in the parent after the |
| 36 | // subprocess exits successfully (caller should return). |
| 37 | func runSubprocess(t *testing.T) bool { |
| 38 | t.Helper() |
| 39 | |
| 40 | if os.Getenv(subprocessEnvKey) == "1" { |
| 41 | return true |
| 42 | } |
| 43 | |
| 44 | ctx := testutil.Context(t, testutil.WaitMedium) |
| 45 | |
| 46 | //nolint:gosec // Test-controlled arguments. |
| 47 | cmd := exec.CommandContext(ctx, os.Args[0], |
| 48 | "-test.run=^"+t.Name()+"$", |
| 49 | "-test.v", |
| 50 | ) |
| 51 | cmd.Env = append(os.Environ(), subprocessEnvKey+"=1") |
| 52 | |
| 53 | out, err := cmd.CombinedOutput() |
| 54 | t.Logf("Subprocess output:\n%s", out) |
| 55 | require.NoError(t, err, "subprocess failed") |
| 56 | |
| 57 | return false |
| 58 | } |
| 59 | |
| 60 | // withDone returns options that stop the reaper goroutine when t |
| 61 | // completes and wait for it to fully exit, preventing |
no test coverage detected