MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / TestStreamableStatelessKeepaliveRace

Function TestStreamableStatelessKeepaliveRace

mcp/streamable_test.go:368–392  ·  view source on GitHub ↗

TestStreamableStatelessKeepaliveRace verifies that there is no data race between ServerSession.startKeepalive and ServerSession.Close in stateless servers.

(t *testing.T)

Source from the content-addressed store, hash-verified

366// TestStreamableStatelessKeepaliveRace verifies that there is no data race between
367// ServerSession.startKeepalive and ServerSession.Close in stateless servers.
368func TestStreamableStatelessKeepaliveRace(t *testing.T) {
369 ctx := context.Background()
370 server := NewServer(testImpl, &ServerOptions{KeepAlive: time.Hour})
371 AddTool(server, &Tool{Name: "greet"}, sayHi)
372 handler := NewStreamableHTTPHandler(
373 func(*http.Request) *Server { return server },
374 &StreamableHTTPOptions{Stateless: true},
375 )
376 httpServer := httptest.NewServer(mustNotPanic(t, handler))
377 defer httpServer.Close()
378
379 for range 50 {
380 cs, err := NewClient(testImpl, nil).Connect(ctx, &StreamableClientTransport{
381 Endpoint: httpServer.URL,
382 }, nil)
383 if err != nil {
384 t.Fatalf("NewClient() failed: %v", err)
385 }
386 _, _ = cs.CallTool(ctx, &CallToolParams{
387 Name: "greet",
388 Arguments: map[string]any{"Name": "world"},
389 })
390 _ = cs.Close()
391 }
392}
393
394// TestClientReplay verifies that the client can recover from a mid-stream
395// network failure and receive replayed messages (if replay is configured). It

Callers

nothing calls this directly

Calls 8

NewServerFunction · 0.85
AddToolFunction · 0.85
NewStreamableHTTPHandlerFunction · 0.85
mustNotPanicFunction · 0.85
NewClientFunction · 0.85
CallToolMethod · 0.80
CloseMethod · 0.65
ConnectMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…