-
Notifications
You must be signed in to change notification settings - Fork 660
/
Copy pathprocess-cleanup.test.ts
63 lines (51 loc) · 1.6 KB
/
process-cleanup.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { execSync } from "node:child_process";
import { Server } from "../server/index.js";
import { StdioServerTransport } from "../server/stdio.js";
import { Client } from "../client/index.js";
import { StdioClientTransport } from "../client/stdio.js";
describe("Process cleanup", () => {
jest.setTimeout(5000); // 5 second timeout
it("server should exit cleanly after closing transport", async () => {
const server = new Server(
{
name: "test-server",
version: "1.0.0",
},
{
capabilities: {},
}
);
const transport = new StdioServerTransport();
await server.connect(transport);
// Close the transport
await transport.close();
// If we reach here without hanging, the test passes
// The test runner will fail if the process hangs
expect(true).toBe(true);
});
it("client should exit cleanly after closing transport", async () => {
const isProcessRunning = (pid: number) => {
try {
execSync(`ps -p ${pid}`, { stdio: 'ignore' });
return true;
/* eslint-disable @typescript-eslint/no-unused-vars */
} catch (error) {
return false;
}
}
const client = new Client({
name: "test-client",
version: "1.0.0",
});
const transport = new StdioClientTransport({
command: "node",
args: ["server-that-hangs.js"],
cwd: __dirname
});
await client.connect(transport);
const pid = transport.pid;
await client.close();
await new Promise(resolve => setTimeout(resolve, 1000));
expect(isProcessRunning(pid!)).toBe(false);
});
});