fix(gateway): bound benchmark teardown waits

This commit is contained in:
Vincent Koc
2026-05-27 03:36:54 +02:00
parent 286964cd6a
commit 1baab3bef5
4 changed files with 156 additions and 20 deletions

View File

@@ -261,6 +261,42 @@ node 1234 user 12u IPv4 0t0 TCP localhost:1234
expect(child.kill).toHaveBeenCalledWith("SIGTERM");
});
it("bounds teardown when the child ignores termination signals", async () => {
const child = new EventEmitter() as EventEmitter & {
exitCode: number | null;
kill: ReturnType<typeof vi.fn>;
signalCode: NodeJS.Signals | null;
stderr: { destroy: ReturnType<typeof vi.fn> };
stdin: { destroy: ReturnType<typeof vi.fn> };
stdout: { destroy: ReturnType<typeof vi.fn> };
unref: ReturnType<typeof vi.fn>;
};
child.exitCode = null;
child.signalCode = null;
child.kill = vi.fn(() => true);
child.stderr = { destroy: vi.fn() };
child.stdin = { destroy: vi.fn() };
child.stdout = { destroy: vi.fn() };
child.unref = vi.fn();
await expect(
testing.stopChild(child as unknown as Parameters<typeof testing.stopChild>[0], {
killGraceMs: 1,
teardownGraceMs: 1,
}),
).resolves.toEqual({
exitedBeforeTeardown: false,
exitCode: null,
signal: "SIGKILL",
});
expect(child.kill).toHaveBeenNthCalledWith(1, "SIGTERM");
expect(child.kill).toHaveBeenNthCalledWith(2, "SIGKILL");
expect(child.stdin.destroy).toHaveBeenCalledOnce();
expect(child.stdout.destroy).toHaveBeenCalledOnce();
expect(child.stderr.destroy).toHaveBeenCalledOnce();
expect(child.unref).toHaveBeenCalledOnce();
});
it("marks clean and signaled pre-teardown child exits as benchmark failures", () => {
expect(
testing.resolveSampleExitFailure({

View File

@@ -325,6 +325,42 @@ describe("gateway startup benchmark script", () => {
expect(child.kill).toHaveBeenCalledWith("SIGTERM");
});
it("bounds teardown when the child ignores termination signals", async () => {
const child = new EventEmitter() as EventEmitter & {
exitCode: number | null;
kill: ReturnType<typeof vi.fn>;
signalCode: NodeJS.Signals | null;
stderr: { destroy: ReturnType<typeof vi.fn> };
stdin: { destroy: ReturnType<typeof vi.fn> };
stdout: { destroy: ReturnType<typeof vi.fn> };
unref: ReturnType<typeof vi.fn>;
};
child.exitCode = null;
child.signalCode = null;
child.kill = vi.fn(() => true);
child.stderr = { destroy: vi.fn() };
child.stdin = { destroy: vi.fn() };
child.stdout = { destroy: vi.fn() };
child.unref = vi.fn();
await expect(
testing.stopChild(child as unknown as Parameters<typeof testing.stopChild>[0], {
killGraceMs: 1,
teardownGraceMs: 1,
}),
).resolves.toEqual({
exitedBeforeTeardown: false,
exitCode: null,
signal: "SIGKILL",
});
expect(child.kill).toHaveBeenNthCalledWith(1, "SIGTERM");
expect(child.kill).toHaveBeenNthCalledWith(2, "SIGKILL");
expect(child.stdin.destroy).toHaveBeenCalledOnce();
expect(child.stdout.destroy).toHaveBeenCalledOnce();
expect(child.stderr.destroy).toHaveBeenCalledOnce();
expect(child.unref).toHaveBeenCalledOnce();
});
it("collects Count-suffixed startup trace metrics", () => {
const startupTrace: Record<string, number> = {};