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)
| 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. |
| 67 | func 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 | } |
no outgoing calls
no test coverage detected