Skip to content

Commit e681bce

Browse files
committed
fix(mcp): use a deterministic clock for discovery timeout test
1 parent 7b01cd8 commit e681bce

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

apps/sim/lib/mcp/client.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @vitest-environment node
33
*/
44
import { UnauthorizedError } from '@modelcontextprotocol/sdk/client/auth.js'
5-
import { beforeEach, describe, expect, it, vi } from 'vitest'
5+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
66

77
const { mockLogger, mockSdkConnect, mockSdkListTools, mockPinnedClose } = vi.hoisted(() => ({
88
mockLogger: {
@@ -100,6 +100,10 @@ describe('McpClient notification handler', () => {
100100
vi.mocked(getMaxExecutionTimeout).mockReturnValue(30_000)
101101
})
102102

103+
afterEach(() => {
104+
vi.useRealTimers()
105+
})
106+
103107
it('preserves authorization-required errors raised by a locked credential reload', async () => {
104108
const error = new McpOauthAuthorizationRequiredError('server-1', 'Test Server')
105109
mockSdkConnect.mockRejectedValueOnce(error)
@@ -199,6 +203,7 @@ describe('McpClient notification handler', () => {
199203
})
200204

201205
it('clamps a configured tools/list timeout to the absolute discovery ceiling', async () => {
206+
vi.useFakeTimers()
202207
vi.mocked(getMaxExecutionTimeout).mockReturnValue(120_000)
203208
const client = new McpClient({
204209
config: { ...createConfig(), timeout: 300_000 },
@@ -210,7 +215,7 @@ describe('McpClient notification handler', () => {
210215

211216
expect(mockSdkListTools).toHaveBeenCalledWith(
212217
undefined,
213-
expect.objectContaining({ timeout: 60_000, maxTotalTimeout: expect.any(Number) })
218+
expect.objectContaining({ timeout: 60_000, maxTotalTimeout: 60_000 })
214219
)
215220
})
216221

0 commit comments

Comments
 (0)