Skip to content

Commit 5a2c8a6

Browse files
v2 flaky test fix (modelcontextprotocol#1616)
1 parent f88c376 commit 5a2c8a6

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

test/integration/test/processCleanup.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Server, StdioServerTransport } from '@modelcontextprotocol/server';
88
const FIXTURES_DIR = path.resolve(__dirname, './__fixtures__');
99

1010
describe('Process cleanup', () => {
11-
vi.setConfig({ testTimeout: 5000 }); // 5 second timeout
11+
vi.setConfig({ testTimeout: 15_000 }); // 15 second timeout (needs margin for CI; close() alone can take ~4s for hanging servers)
1212

1313
it('server should exit cleanly after closing transport', async () => {
1414
const server = new Server(

test/integration/test/server/cloudflareWorkers.test.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,28 @@ export default {
150150
it('should handle MCP requests', async () => {
151151
expect(env).not.toBeNull();
152152

153-
const client = new Client({ name: 'test-client', version: '1.0.0' });
154-
const transport = new StreamableHTTPClientTransport(new URL(`http://127.0.0.1:${PORT}/`));
155-
156-
await client.connect(transport);
153+
// Retry connection — wrangler may report "Ready" before it can handle requests
154+
let client!: Client;
155+
let lastError: unknown;
156+
for (let attempt = 0; attempt < 5; attempt++) {
157+
try {
158+
client = new Client({ name: 'test-client', version: '1.0.0' });
159+
const transport = new StreamableHTTPClientTransport(new URL(`http://127.0.0.1:${PORT}/`));
160+
await client.connect(transport);
161+
lastError = undefined;
162+
break;
163+
} catch (error) {
164+
lastError = error;
165+
await new Promise(resolve => setTimeout(resolve, 1000));
166+
}
167+
}
168+
if (lastError) {
169+
throw lastError;
170+
}
157171

158172
const result = await client.callTool({ name: 'greet', arguments: { name: 'World' } });
159173
expect(result.content).toEqual([{ type: 'text', text: 'Hello, World!' }]);
160174

161175
await client.close();
162-
});
176+
}, 30_000);
163177
});

0 commit comments

Comments
 (0)