From 6fa02550afcb698421b6757ed22a352d8ce3c98c Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 11 Nov 2026 04:25:27 +0800 Subject: [PATCH] gateway: TestServingGatesTools waits for the gate, not the listener (#6016) ListenAndServe sets s.ln, then loads rests, acks, observers and groups, and only then takes gwtool.Gate(), before the HTTP server starts. The test waited for s.ln and checked Served at once, so on a loaded machine it checked in that gap and read web search as still served. That was the one red in a full -race run of internal/gateway on mote (2272s). No user sees the gap: nothing is served before the gate is taken. So the test now waits, up to its own 10s, for the gate to close, and still fails if it never does. Run on mote: - with time.Sleep(300ms) injected after `s.ln = ln`: the old test red (search_plugin_test.go:151), this one green, -count=3 each; - go vet -tags nogui ./internal/gateway; gofmt -l clean; - go test -tags nogui -race -count=5 -run 'TestServingGatesTools$|Gate' ./internal/gateway: ok (150s). Not run: the full suite again; the full -race gateway run before this had this test as its only red. --- internal/gateway/search_plugin_test.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/gateway/search_plugin_test.go b/internal/gateway/search_plugin_test.go index e0a6be355..77c8dd80f 100644 --- a/internal/gateway/search_plugin_test.go +++ b/internal/gateway/search_plugin_test.go @@ -147,8 +147,16 @@ func TestServingGatesTools(t *testing.T) { } time.Sleep(10 * time.Millisecond) } - if gwtool.Served(gwtool.WebSearch) { - t.Error("serving, with the plugin off: web search still served") + // the listener is set before ListenAndServe gates the tools, and the + // HTTP server only starts after: wait for the gate, not for the + // listener (#6016, red in a full -race run on a loaded mote) + deadline = time.Now().Add(10 * time.Second) + for gwtool.Served(gwtool.WebSearch) { + if time.Now().After(deadline) { + t.Error("serving, with the plugin off: web search still served") + break + } + time.Sleep(time.Millisecond) } cancel() if err := <-done; err != nil {