mcp: re-enable race test after fixing data races (#851)

1. (non-test) Don't queue notifications if there are no connected
sessions.
2. Change `reconnectInitialDelay` to be atomic, as it is modified in
tests.
3. Protect map access with mutex in `TestServerTransportCleanup`.
This commit is contained in:
Maciej Kisiel 2026-03-23 08:35:27 +01:00 • committed by GitHub
commit 755b9ed4df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -626,7 +626,10 @@ func TestServerTransportCleanup(t *testing.T) {
handler := NewStreamableHTTPHandler(func(*http.Request) *Server { return server }, nil)
handler.onTransportDeletion = func(sessionID string) {
chans[sessionID] <- struct{}{}
mu.Lock()
ch := chans[sessionID]
mu.Unlock()
ch <- struct{}{}
}
httpServer := httptest.NewServer(mustNotPanic(t, handler))
@ -658,7 +661,11 @@ func TestServerTransportCleanup(t *testing.T) {
t.Cleanup(func() { _ = clientSession.Close() })
}
for _, ch := range chans {
mu.Lock()
channels := slices.Collect(maps.Values(chans))
mu.Unlock()
for _, ch := range channels {
select {
case <-ctx.Done():
t.Errorf("did not capture transport deletion event from all session in 10 seconds")