From f454ebe329a30575f41ce4c9ac86328590db8b2f Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Wed, 18 Nov 2026 11:00:00 -0600 Subject: [PATCH] test(mcpx): wait for supervised child reap after detach --- .../internal/pool/supervised_default_test.go | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/pkgs/mcpx/internal/pool/supervised_default_test.go b/pkgs/mcpx/internal/pool/supervised_default_test.go index db7a3e1473..aac21d04d6 100644 --- a/pkgs/mcpx/internal/pool/supervised_default_test.go +++ b/pkgs/mcpx/internal/pool/supervised_default_test.go @@ -2,6 +2,7 @@ package pool_test import ( "context" + "errors" "net" "os" "path/filepath" @@ -60,19 +61,26 @@ func TestDefaultConfigStdioRunsSupervised(t *testing.T) { t.Fatalf("status instances = %+v, want one with a child pid", st.Instances) } childPID := st.Instances[0].PID + // An attached daemon owns this supervisor: a scan during pool shutdown + // can legitimately be refused until the transport finishes detaching. + outcomes := mcpclient.ScanSupervisorSockets(stateDir, nil, nil) + if len(outcomes) != 1 || outcomes[0].Action != "refused" { + t.Fatalf("scan while attached = %+v, want one refused supervisor", outcomes) + } lease.Release() p.Close() // The child survives the pool (that is the point of supervised); - // reap it through the scan so the test leaves nothing behind. - // The reap is acknowledged before the supervisor finishes the - // kill, so wait for the child to actually exit. - mcpclient.ScanSupervisorSockets(stateDir, nil, nil) - deadline := time.Now().Add(10 * time.Second) - for syscall.Kill(childPID, 0) == nil { - if time.Now().After(deadline) { - t.Fatalf("supervised child %d still alive after the reap", childPID) - } - time.Sleep(20 * time.Millisecond) + // reap it through the scan so the test leaves nothing behind. Closing + // the pool's connection detaches asynchronously; StopSupervisors retries + // a refusal while that detach finishes and waits for the child to be + // reaped before returning. + if err := testsupport.StopSupervisors(stateDir); err != nil { + t.Fatalf("stop supervised child: %v", err) + } + if err := syscall.Kill(childPID, 0); err == nil { + t.Fatalf("supervised child %d still alive after the reap", childPID) + } else if !errors.Is(err, syscall.ESRCH) { + t.Fatalf("check supervised child %d after the reap: %v", childPID, err) } }