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

Function TestServerInterrupt

mcp/cmd_test.go:120–151  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

118}
119
120func TestServerInterrupt(t *testing.T) {
121 if runtime.GOOS == "windows" {
122 t.Skip("requires POSIX signals")
123 }
124 requireExec(t)
125
126 t.Log("Starting server command")
127 cmd := createServerCommand(t, "default")
128
129 client := mcp.NewClient(testImpl, nil)
130 t.Log("Connecting to server")
131
132 ctx := context.Background()
133 session, err := client.Connect(ctx, &mcp.CommandTransport{Command: cmd}, nil)
134 if err != nil {
135 t.Fatal(err)
136 }
137
138 t.Log("Send a signal to the server process to terminate it")
139 if err := cmd.Process.Signal(os.Interrupt); err != nil {
140 t.Fatal(err)
141 }
142
143 t.Log("Closing client session so server can exit immediately")
144 session.Close()
145
146 t.Log("Wait for process to terminate after interrupt signal")
147 _, err = cmd.Process.Wait()
148 if err == nil {
149 t.Errorf("unexpected error: %v", err)
150 }
151}
152
153func TestStdioContextCancellation(t *testing.T) {
154 if runtime.GOOS == "windows" {

Callers

nothing calls this directly

Calls 7

ConnectMethod · 0.95
NewClientFunction · 0.92
requireExecFunction · 0.85
createServerCommandFunction · 0.85
LogMethod · 0.80
CloseMethod · 0.65
WaitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…