mcp: fix goroutine leaks in unit tests (#496)
This PR fixes goroutine leaks in all unit tests. To find the leaks I integrated https://github.com/uber-go/goleak and I suggest to keep using it to catch any future regressions. I used the folowing script to more easily find individual tests which were leaking goroutines: ``` for t in $(go test -run=Nothing -list=. ./mcp | grep -v ok); do go test ./mcp -run="$t" > /dev/null && echo -n . || echo -e "\nDetected leak: $t"; done ```
This commit is contained in:
parent
14e776db6f
commit
010bdbc64d
1 changed files with 72 additions and 54 deletions
|
|
@ -25,7 +25,7 @@ func TestBatchFraming(t *testing.T) {
|
|||
r, w := io.Pipe()
|
||||
tport := newIOConn(rwc{r, w})
|
||||
tport.outgoingBatch = make([]jsonrpc.Message, 0, 2)
|
||||
defer tport.Close()
|
||||
t.Cleanup(func() { tport.Close() })
|
||||
|
||||
// Read the two messages into a channel, for easy testing later.
|
||||
read := make(chan jsonrpc.Message)
|
||||
|
|
@ -101,6 +101,7 @@ func TestIOConnRead(t *testing.T) {
|
|||
tr := newIOConn(rwc{
|
||||
rc: io.NopCloser(strings.NewReader(tt.input)),
|
||||
})
|
||||
t.Cleanup(func() { tr.Close() })
|
||||
if tt.protocolVersion != "" {
|
||||
tr.sessionUpdated(ServerSessionState{
|
||||
InitializeParams: &InitializeParams{
|
||||
|
|
|
|||
Loading…
Reference in a new issue