TestReload_NoopWhenUnchanged verifies that Reload returns immediately without reconnecting when the snapshot is fresh.
(t *testing.T)
| 645 | // TestReload_NoopWhenUnchanged verifies that Reload returns |
| 646 | // immediately without reconnecting when the snapshot is fresh. |
| 647 | func 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 |
nothing calls this directly
no test coverage detected