MCPcopy Index your code
hub / github.com/coder/coder / runSubprocess

Function runSubprocess

agent/reaper/reaper_test.go:37–58  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

35// the real test logic). Returns false in the parent after the
36// subprocess exits successfully (caller should return).
37func 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

Callers 3

TestReapFunction · 0.85
TestForkReapExitCodesFunction · 0.85
TestReapInterruptFunction · 0.85

Calls 6

ContextFunction · 0.92
HelperMethod · 0.65
CommandContextMethod · 0.65
NameMethod · 0.65
EnvironMethod · 0.65
LogfMethod · 0.65

Tested by

no test coverage detected