v2 flaky test fix (#1616)

This commit is contained in:
Konstantin Konstantinov 2026-03-05 00:55:02 +02:00 • committed by GitHub
commit 5a2c8a69c9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 6 deletions

View file

@ -8,7 +8,7 @@ import { Server, StdioServerTransport } from '@modelcontextprotocol/server';
const FIXTURES_DIR = path.resolve(__dirname, './__fixtures__');
describe('Process cleanup', () => {
vi.setConfig({ testTimeout: 5000 }); // 5 second timeout
vi.setConfig({ testTimeout: 15_000 }); // 15 second timeout (needs margin for CI; close() alone can take ~4s for hanging servers)
it('server should exit cleanly after closing transport', async () => {
const server = new Server(

View file

@ -150,14 +150,28 @@ export default {
it('should handle MCP requests', async () => {
expect(env).not.toBeNull();
const client = new Client({ name: 'test-client', version: '1.0.0' });
const transport = new StreamableHTTPClientTransport(new URL(`http://127.0.0.1:${PORT}/`));
await client.connect(transport);
// Retry connection — wrangler may report "Ready" before it can handle requests
let client!: Client;
let lastError: unknown;
for (let attempt = 0; attempt < 5; attempt++) {
try {
client = new Client({ name: 'test-client', version: '1.0.0' });
const transport = new StreamableHTTPClientTransport(new URL(`http://127.0.0.1:${PORT}/`));
await client.connect(transport);
lastError = undefined;
break;
} catch (error) {
lastError = error;
await new Promise(resolve => setTimeout(resolve, 1000));
}
}
if (lastError) {
throw lastError;
}
const result = await client.callTool({ name: 'greet', arguments: { name: 'World' } });
expect(result.content).toEqual([{ type: 'text', text: 'Hello, World!' }]);
await client.close();
});
}, 30_000);
});