gateway: a Claude TUI test's unanswered call ends with its test
tuiCalls.call made Claude Code's MCP call with httptest.NewRequest, whose context is never done, so a call a test didn't answer waited in mcpCall until the package ended. macOS CI's 30m alarm ate787e7b5c(run 43102520567) showed one such goroutine blocked 24 minutes in mcpCall from claude_tui_call_test.go:76. The request now carries a context the test's cleanup cancels, and the cleanup waits for the call to return. Run (mote, at origin/main152734cd1plus this change): a throwaway probe test, run after the TUI tests, counting (*tuiCalls).call goroutines still alive: old helper "1 tuiCalls calls still running after their tests", fixed helper ok. go test -race -count=5 -run TestClaudeTUI ./internal/gateway ok (240s); that pattern covers every user of newTUICalls and schemaTUI. Not the cause of that run's timeout: the package took 1801s where the last green macOS run took 888s, with the alarm landing on a 5s-old ZCode test (#2191).
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http/httptest"
|
||||
@@ -64,6 +65,9 @@ func (c *tuiCalls) write(lines ...string) {
|
||||
func (c *tuiCalls) call(id, args string) {
|
||||
done := make(chan struct{})
|
||||
c.called[id] = done
|
||||
// a call the test never answers ends with the test, not the package
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
c.t.Cleanup(func() { cancel(); <-done })
|
||||
go func() {
|
||||
defer close(done)
|
||||
body := `{"tool_call_id":"` + id + `","name":"Read"`
|
||||
@@ -71,7 +75,7 @@ func (c *tuiCalls) call(id, args string) {
|
||||
body += `,"arguments":` + args
|
||||
}
|
||||
body += `}`
|
||||
r := httptest.NewRequest("POST", "/", strings.NewReader(body))
|
||||
r := httptest.NewRequestWithContext(ctx, "POST", "/", strings.NewReader(body))
|
||||
r.SetPathValue("token", "run")
|
||||
c.bridge.mcpCall(httptest.NewRecorder(), r)
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user