Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions tests/unit/test-utils/process-table.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,25 @@ describe('process-table helper (issue #885)', () => {
return proc;
}

/** A just-spawned process takes a moment to appear in the OS process table (seconds on a cold CI runner). */
async function waitUntilListed(pid: number, image: string, timeoutMs: number): Promise<number[]> {
const deadline = Date.now() + timeoutMs;
let listed = await listPidsByImage(image);
while (!listed.includes(pid) && Date.now() < deadline) {
await new Promise((resolve) => setTimeout(resolve, 250));
listed = await listPidsByImage(image);
}
return listed;
}

it('lists a live node child under its image and sees it alive', async () => {
const proc = spawnIdleNode();
expect(isProcessAlive(proc.pid!)).toBe(true);
expect(await listPidsByImage('node')).toContain(proc.pid);
});
// Not asserted on the first scan: on windows-latest the child was alive
// but not yet in the table when queried right after spawn (main CI on
// 42651425), while a scan 300 ms later listed it.
expect(await waitUntilListed(proc.pid!, 'node', 15_000)).toContain(proc.pid);
}, 30_000);

it('answers the pid as a survivor only while it is still a process of the named image', async () => {
const proc = spawnIdleNode();
Expand Down
Loading