diff --git a/app/go-cli/internal/cli/root_prerun_backup_linux_test.go b/app/go-cli/internal/cli/root_prerun_backup_linux_test.go index c85c9e6..37b9a93 100644 --- a/app/go-cli/internal/cli/root_prerun_backup_linux_test.go +++ b/app/go-cli/internal/cli/root_prerun_backup_linux_test.go @@ -492,9 +492,11 @@ func TestDefaultPreRunCommandKillsGrandchildOnDeadline(t *testing.T) { go func() { done <- command.Run() }() var childPID int for time.Now().Before(started.Add(4 * time.Second)) { + // os.WriteFile creates the file before writing it: an empty or partial + // read means the helper has not finished, so keep polling. body, err := os.ReadFile(preRunTestPIDPath) - if err == nil { - childPID, _ = strconv.Atoi(string(body)) + if pid, parseErr := strconv.Atoi(string(body)); err == nil && parseErr == nil && pid > 0 { + childPID = pid break } time.Sleep(10 * time.Millisecond)