mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
* fix(cli): closing the managed Chrome also ends the helper processes it leaves behind The close waited a second for Chrome to exit and then killed only Chrome's own process. Under load that second is often not enough, and the helpers (the GPU and renderer processes, crashpad_handler) were reparented to init and kept running after a finished run. The close now records the processes under Chrome before it starts, and ends any of them still running (under the same command) once Chrome is gone. * test(cli): the helper-reaping test polls for the helper's exit instead of waiting 200 ms * fix(cli): the Chrome process listing is bounded and no longer runs at import The ps call that records Chrome's helpers ran with no time limit before the bounded browser close, so a stalled ps made the close unbounded. It now has a 2 s limit, and a timeout records no helpers. execFile is resolved when ps runs, not when the module loads, so tests that mock node:child_process without execFile import it again.
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
|
|
const execFile = vi.hoisted(() => vi.fn());
|
|
vi.mock("node:child_process", () => ({ execFile }));
|
|
|
|
import { chromeDescendants, reapChromeTree } from "./chromeTree.js";
|
|
|
|
const psFails = (error: Error & { killed?: boolean }) =>
|
|
execFile.mockImplementation((...args: unknown[]) => {
|
|
(args.at(-1) as (e: Error) => void)(error);
|
|
});
|
|
|
|
describe("chromeTree ps call", () => {
|
|
it("is bounded, and a ps killed at the timeout records no descendants", async () => {
|
|
psFails(Object.assign(new Error("ps timed out"), { killed: true }));
|
|
await expect(chromeDescendants(1)).resolves.toEqual([]);
|
|
expect(execFile.mock.calls[0]?.[2]).toMatchObject({ timeout: expect.any(Number) });
|
|
});
|
|
|
|
it("does not hide other ps failures", async () => {
|
|
psFails(new Error("spawn ps ENOENT"));
|
|
await expect(chromeDescendants(1)).rejects.toThrow("ENOENT");
|
|
});
|
|
|
|
it("reaps nothing without running ps when no member was recorded", async () => {
|
|
execFile.mockClear();
|
|
await reapChromeTree([]);
|
|
expect(execFile).not.toHaveBeenCalled();
|
|
});
|
|
});
|