MCPcopy Create free account
hub / github.com/codehamr/codehamr / waitForPID

Function waitForPID

internal/tools/bash_procgroup_unix_test.go:67–81  ·  view source on GitHub ↗

waitForPID blocks until pidFile contains a parseable PID, then returns it. Fails the test if the file never appears within a short deadline.

(t *testing.T, pidFile string)

Source from the content-addressed store, hash-verified

65// waitForPID blocks until pidFile contains a parseable PID, then returns it.
66// Fails the test if the file never appears within a short deadline.
67func waitForPID(t *testing.T, pidFile string) int {
68 t.Helper()
69 deadline := time.Now().Add(5 * time.Second)
70 for time.Now().Before(deadline) {
71 raw, err := os.ReadFile(pidFile)
72 if err == nil {
73 if pid, perr := strconv.Atoi(strings.TrimSpace(string(raw))); perr == nil && pid > 0 {
74 return pid
75 }
76 }
77 time.Sleep(10 * time.Millisecond)
78 }
79 t.Fatalf("child PID file %s never appeared", pidFile)
80 return 0
81}

Calls

no outgoing calls

Tested by

no test coverage detected