MCPcopy
hub / github.com/docker/docker-agent / TestRemoteToolsetReconnectsAfterCleanClose

Function TestRemoteToolsetReconnectsAfterCleanClose

pkg/tools/mcp/mcp_test.go:639–675  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

637}
638
639func TestRemoteToolsetReconnectsAfterCleanClose(t *testing.T) {
640 t.Parallel()
641
642 pingTool := &mcp.Tool{Name: "ping"}
643 mock := &failingInitClient{
644 toolsToList: []*mcp.Tool{pingTool},
645 waitCh: make(chan struct{}),
646 }
647
648 ts := newTestToolset("test-remote", "remote-server", mock)
649 ts.supervisor = newSupervisor(ts, lifecycle.Policy{
650 Restart: lifecycle.RestartAlways,
651 Backoff: lifecycle.Backoff{
652 Initial: time.Millisecond,
653 Max: 2 * time.Millisecond,
654 Multiplier: 2,
655 },
656 })
657
658 require.NoError(t, ts.Start(t.Context()))
659 require.True(t, ts.IsStarted())
660
661 require.NoError(t, mock.Close(t.Context()))
662 require.Eventually(t, func() bool {
663 mock.mu.Lock()
664 initCalls := mock.initCalls
665 mock.mu.Unlock()
666 return initCalls >= 2 && ts.IsStarted()
667 }, 2*time.Second, 10*time.Millisecond, "remote toolset did not reconnect after clean close")
668
669 toolList, err := ts.Tools(t.Context())
670 require.NoError(t, err)
671 require.Len(t, toolList, 1)
672 assert.Equal(t, "test-remote_ping", toolList[0].Name)
673
674 _ = ts.Stop(t.Context())
675}

Callers

nothing calls this directly

Calls 11

CloseMethod · 0.95
newTestToolsetFunction · 0.85
newSupervisorFunction · 0.85
ContextMethod · 0.80
StartMethod · 0.65
IsStartedMethod · 0.65
ToolsMethod · 0.65
LenMethod · 0.65
StopMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected