Align MCP tests with repo style and stabilize external test process handling
This commit is contained in:
parent
5c073feeba
commit
431039a9dd
2 changed files with 8 additions and 12 deletions
|
|
@ -3,6 +3,7 @@ package tools
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
@ -128,7 +129,7 @@ func TestMCPExternalPopularEverythingSSE(t *testing.T) {
|
||||||
requireExternalMCPTests(t)
|
requireExternalMCPTests(t)
|
||||||
|
|
||||||
port := pickFreePort(t)
|
port := pickFreePort(t)
|
||||||
cmd := startEverythingServer(t, port, "sse")
|
startEverythingServer(t, port, "sse")
|
||||||
waitForTCPPort(t, fmt.Sprintf("127.0.0.1:%d", port), 15*time.Second)
|
waitForTCPPort(t, fmt.Sprintf("127.0.0.1:%d", port), 15*time.Second)
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
||||||
|
|
@ -167,14 +168,13 @@ func TestMCPExternalPopularEverythingSSE(t *testing.T) {
|
||||||
t.Fatalf("unexpected echo output: %s", out)
|
t.Fatalf("unexpected echo output: %s", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = cmd
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMCPExternalPopularEverythingStreamableHTTP(t *testing.T) {
|
func TestMCPExternalPopularEverythingStreamableHTTP(t *testing.T) {
|
||||||
requireExternalMCPTests(t)
|
requireExternalMCPTests(t)
|
||||||
|
|
||||||
port := pickFreePort(t)
|
port := pickFreePort(t)
|
||||||
cmd := startEverythingServer(t, port, "streamableHttp")
|
startEverythingServer(t, port, "streamableHttp")
|
||||||
waitForTCPPort(t, fmt.Sprintf("127.0.0.1:%d", port), 15*time.Second)
|
waitForTCPPort(t, fmt.Sprintf("127.0.0.1:%d", port), 15*time.Second)
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
||||||
|
|
@ -213,7 +213,6 @@ func TestMCPExternalPopularEverythingStreamableHTTP(t *testing.T) {
|
||||||
t.Fatalf("unexpected echo output: %s", out)
|
t.Fatalf("unexpected echo output: %s", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = cmd
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func requireExternalMCPTests(t *testing.T) {
|
func requireExternalMCPTests(t *testing.T) {
|
||||||
|
|
@ -264,13 +263,13 @@ func waitForTCPPort(t *testing.T, addr string, timeout time.Duration) {
|
||||||
t.Fatalf("port %s did not become ready within %v", addr, timeout)
|
t.Fatalf("port %s did not become ready within %v", addr, timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
func startEverythingServer(t *testing.T, port int, mode string) *exec.Cmd {
|
func startEverythingServer(t *testing.T, port int, mode string) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
cmd := exec.Command("npx", "-y", "@modelcontextprotocol/server-everything", mode)
|
cmd := exec.Command("npx", "-y", "@modelcontextprotocol/server-everything", mode)
|
||||||
cmd.Env = append(os.Environ(), fmt.Sprintf("PORT=%d", port))
|
cmd.Env = append(os.Environ(), fmt.Sprintf("PORT=%d", port))
|
||||||
cmd.Stdout = os.Stderr
|
cmd.Stdout = io.Discard
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = io.Discard
|
||||||
|
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
t.Fatalf("start everything %s server: %v", mode, err)
|
t.Fatalf("start everything %s server: %v", mode, err)
|
||||||
|
|
@ -284,5 +283,4 @@ func startEverythingServer(t *testing.T, port int, mode string) *exec.Cmd {
|
||||||
_, _ = cmd.Process.Wait()
|
_, _ = cmd.Process.Wait()
|
||||||
})
|
})
|
||||||
|
|
||||||
return cmd
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -173,8 +173,7 @@ func TestBuildTransport_CommandTerminateDefaults(t *testing.T) {
|
||||||
Name: "default-terminate",
|
Name: "default-terminate",
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Transport: "command",
|
Transport: "command",
|
||||||
Command: "sleep",
|
Command: "test-command",
|
||||||
Args: []string{"1"},
|
|
||||||
}, "")
|
}, "")
|
||||||
|
|
||||||
tr, err := client.buildTransport()
|
tr, err := client.buildTransport()
|
||||||
|
|
@ -196,8 +195,7 @@ func TestBuildTransport_CommandTerminateOverride(t *testing.T) {
|
||||||
Name: "override-terminate",
|
Name: "override-terminate",
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Transport: "command",
|
Transport: "command",
|
||||||
Command: "sleep",
|
Command: "test-command",
|
||||||
Args: []string{"1"},
|
|
||||||
TerminateTimeoutMS: 2500,
|
TerminateTimeoutMS: 2500,
|
||||||
}, "")
|
}, "")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue