Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions pkg/command/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,15 @@ func TestKillTreeTerminatesGroupAfterWorkerExits(t *testing.T) {
}
t.Cleanup(func() { _ = killTreeAfterWorkerExit(workerPID, "detached-task", identity) })

childPID := readTestPID(t, childPIDFile)

if err := cmd.Wait(); err != nil {
t.Fatalf("wait for worker exit: %v", err)
}
// #nosec G304 -- the exited worker has finished writing its own temporary PID file.
data, err := os.ReadFile(childPIDFile)
if err != nil {
t.Fatalf("read child PID: %v", err)
}
childPID := strings.TrimSpace(string(data))
waitForTestProcess(t, childPID, true)

if err := killTreeAfterWorkerExit(workerPID, "detached-task", identity); err != nil {
Expand Down Expand Up @@ -229,21 +233,6 @@ func processTreeIdentityForTest(t *testing.T, pid int) string {
return identity
}

func readTestPID(t *testing.T, path string) string {
t.Helper()
deadline := time.Now().Add(5 * time.Second)
for time.Now().Before(deadline) {
// #nosec G304 -- this test reads only its own temporary PID file.
data, err := os.ReadFile(path)
if err == nil {
return strings.TrimSpace(string(data))
}
time.Sleep(10 * time.Millisecond)
}
t.Fatalf("worker did not publish PID in %s", path)
return ""
}

func waitForTestProcess(t *testing.T, pid string, wantRunning bool) {
t.Helper()
deadline := time.Now().Add(5 * time.Second)
Expand Down
Loading