MCPcopy Create free account
hub / github.com/coder/coder / TestReload_NoopWhenUnchanged

Function TestReload_NoopWhenUnchanged

agent/x/agentmcp/reload_internal_test.go:647–687  ·  view source on GitHub ↗

TestReload_NoopWhenUnchanged verifies that Reload returns immediately without reconnecting when the snapshot is fresh.

(t *testing.T)

Source from the content-addressed store, hash-verified

645// TestReload_NoopWhenUnchanged verifies that Reload returns
646// immediately without reconnecting when the snapshot is fresh.
647func TestReload_NoopWhenUnchanged(t *testing.T) {
648 t.Parallel()
649
650 if os.Getenv("TEST_MCP_FAKE_SERVER") == "1" {
651 runFakeMCPServer()
652 return
653 }
654
655 ctx := testutil.Context(t, testutil.WaitLong)
656 logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
657 dir := t.TempDir()
658
659 _, entry := fakeMCPServerConfig(t, "srv")
660 configPath := writeMCPConfig(t, dir, map[string]mcpServerEntry{"srv": entry})
661
662 m := NewManager(ctx, logger, agentexec.DefaultExecer, nil)
663 t.Cleanup(func() { _ = m.Close() })
664
665 err := m.Reload(ctx, []string{configPath})
666 require.NoError(t, err)
667
668 m.mu.RLock()
669 origClient := m.servers["srv"].client
670 m.mu.RUnlock()
671
672 // Second reload with no changes should be a no-op.
673 err = m.Reload(ctx, []string{configPath})
674 require.NoError(t, err)
675
676 callerCtx, cancel := context.WithCancel(ctx)
677 cancel()
678 err = m.Reload(callerCtx, []string{configPath})
679 require.NoError(t, err)
680
681 m.mu.RLock()
682 sameClient := m.servers["srv"].client
683 m.mu.RUnlock()
684
685 assert.Same(t, origClient, sameClient,
686 "no-op reload should not replace the client")
687}
688
689// TestClose_SuppressesSubprocessExitError verifies that Close
690// returns nil when servers have running subprocesses that exit

Callers

nothing calls this directly

Calls 9

CloseMethod · 0.95
ReloadMethod · 0.95
ContextFunction · 0.92
runFakeMCPServerFunction · 0.85
fakeMCPServerConfigFunction · 0.85
writeMCPConfigFunction · 0.85
NewManagerFunction · 0.70
TempDirMethod · 0.65
CleanupMethod · 0.65

Tested by

no test coverage detected