From a2c85e588ae1509600d0885dc1cd1413e1063568 Mon Sep 17 00:00:00 2001 From: Muse Sweep Date: Sun, 18 Oct 2026 21:55:59 -0500 Subject: [PATCH] test(mcpx): poll the upgrade-reap pid file until the pid lands (dezren39/nix#442) Mirror of the dezren39/nix fix for the identical copy: the poll broke on the first successful ReadFile and parsed the content once, outside the loop, so a pid file that existed before its pid landed failed the test with a bare strconv.Atoi error instead of waiting. Poll until the content parses; on the deadline, fail naming the pid file. --- pkgs/mcpx/internal/daemon/upgrade_test.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/pkgs/mcpx/internal/daemon/upgrade_test.go b/pkgs/mcpx/internal/daemon/upgrade_test.go index ec91ef0cf7..d658d4874b 100644 --- a/pkgs/mcpx/internal/daemon/upgrade_test.go +++ b/pkgs/mcpx/internal/daemon/upgrade_test.go @@ -151,24 +151,25 @@ func TestUpgradeSuccessorThatDoesNotDialBackIsReaped(t *testing.T) { } // The successor is a separate process; poll briefly for its pid // file rather than assuming it was scheduled before the HTTP - // answer returned (the #428 pattern). - var raw []byte + // answer returned (the #428 pattern). The file can also exist + // before its pid does: a successor descheduled between creating + // the file and writing the pid leaves it empty, so poll until + // the content parses, not merely until the file appears. + var pid int deadline := time.Now().Add(5 * time.Second) for { - var err error - raw, err = os.ReadFile(pidFile) + raw, err := os.ReadFile(pidFile) if err == nil { - break + if n, aerr := strconv.Atoi(strings.TrimSpace(string(raw))); aerr == nil { + pid = n + break + } } if time.Now().After(deadline) { - t.Fatalf("the successor did not run: %v", err) + t.Fatalf("the successor did not write its pid to %s", pidFile) } time.Sleep(10 * time.Millisecond) } - pid, err := strconv.Atoi(strings.TrimSpace(string(raw))) - if err != nil { - t.Fatal(err) - } if err := syscall.Kill(pid, 0); !errors.Is(err, syscall.ESRCH) { t.Fatalf("the abandoned successor %d was not reaped: %v", pid, err) }