Файли
openidea/perf/lib/lifecycle.test.ts
T
Mr0Bread 34cb4ad5e0 fix(bench): preserve failed trials and bound cleanup (#4489)
Failed warmups and repetitions were dropped from benchmark summaries, a failed startup, build or cleanup could leave an earlier success report in place, and a hung renderer or child process could block a run. Every attempt now keeps its status, metrics and error so summaries have the complete denominator; failures replace stale reports; browser and child-process lifecycles are bounded with cleanup of owned resources; and each criterion execution gets its own artifact directory.

Co-authored-by: Mr0Bread <[email protected]>
2026-11-19 19:38:34 +08:00

43 рядки
1.5 KiB
TypeScript

// @vitest-environment node
import { expect, test, vi } from "vitest";
import { launchBrowser, withDeadline } from "./lifecycle.ts";
test("a deadline rejects an unanswered operation and releases its timer", async () => {
vi.useFakeTimers();
try {
const pending = withDeadline(Promise.withResolvers<void>().promise, 20, "RPC");
const assertion = expect(pending).rejects.toThrow("RPC timed out after 20 ms");
await vi.advanceTimersByTimeAsync(20);
await assertion;
expect(vi.getTimerCount()).toBe(0);
} finally {
vi.useRealTimers();
}
});
test.each(["blocked renderer", "missing animation frames"])(
"Node deadline survives %s and browser cleanup terminates it",
{ timeout: 20_000 },
async (mode) => {
const runtime = await launchBrowser({ headless: true });
try {
const page = await runtime.browser.newPage();
// Real renderer/Node clocks are the boundary under test; fake timers cannot drive Chromium.
const operation =
mode === "blocked renderer"
? page.evaluate(() => {
for (;;) {
/* Deliberately unresponsive renderer. */
}
})
: page.evaluate(() => {
window.requestAnimationFrame = () => 0;
return new Promise<void>((resolve) => requestAnimationFrame(() => resolve()));
});
await expect(withDeadline(operation, 30, mode)).rejects.toThrow("wall clock");
} finally {
await runtime.close();
}
},
);