diff --git a/pkgs/mcpx/internal/cli/ensuredaemon_test.go b/pkgs/mcpx/internal/cli/ensuredaemon_test.go index 94ccd3ebce..1ceaf5d78d 100644 --- a/pkgs/mcpx/internal/cli/ensuredaemon_test.go +++ b/pkgs/mcpx/internal/cli/ensuredaemon_test.go @@ -88,8 +88,24 @@ func TestEnsureDaemonNeverReadyStillTimesOut(t *testing.T) { if elapsed := time.Since(start); elapsed < 900*time.Millisecond { t.Fatalf("gave up after %v, before the 1s connect timeout", elapsed) } - if _, statErr := os.Stat(marker); statErr != nil { - t.Fatal("the fake daemon was never spawned") + // The spawn is cmd.Start + Release (client.go): Start returns once the + // process exists, before the child has run any code, so the child's + // touch can legitimately land after EnsureDaemon returns at the + // connect timeout. Asserting the marker instantly races the child's + // scheduling — the same flake as dezren39/nix#428, in the test this + // repo's #437 port added without that pattern (dezren39/nix#445, + // origin issue for this set). The child is Setsid and Released, so it + // still runs: wait for the marker instead, and fail only if it never + // appears. + deadline := time.Now().Add(5 * time.Second) + for { + if _, statErr := os.Stat(marker); statErr == nil { + break + } + if time.Now().After(deadline) { + t.Fatal("the fake daemon was never spawned") + } + time.Sleep(10 * time.Millisecond) } }