From 3264124397a84f31bc60b47a21ce5d80a14bd304 Mon Sep 17 00:00:00 2001 From: Muse Sweep Date: Sun, 18 Oct 2026 23:27:23 -0500 Subject: [PATCH] test(mcpx): poll for the fake daemon's marker in TestEnsureDaemonNeverReadyStillTimesOut (dezren39/nix#445) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test asserted the marker file the instant EnsureDaemon returned at the 1s connect timeout, but the spawn is cmd.Start + Release: Start returns before the child has run any code, so the child's touch can legitimately land after the return — the same race dezren39/nix#428 fixed in TestEnsureDaemonCancelWhilePolling. Poll for the marker (10ms, 5s deadline) and fail only if it never appears. Reproduced deterministically with the dezren39/nix#428 amplification technique (fake daemon's touch delayed 2s): pre-fix FAIL at the instant stat, post-fix PASS. Origin issue for the set: https://github.com/dezren39/nix/issues/445 --- pkgs/mcpx/internal/cli/ensuredaemon_test.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) 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) } }