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.
This commit is contained in:
yetone
2026-11-11 04:25:27 +08:00
parent 51da6f1f5c
commit 6fa02550af
+10 -2
View File
@@ -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 {