perf(test): optimize heavy suites and stabilize lock timing

This commit is contained in:
Peter Steinberger
2026-02-13 13:28:23 +00:00
parent 8307f9738b
commit 8899f9e94a
14 changed files with 476 additions and 702 deletions

View File

@@ -1,11 +1,19 @@
import { describe, expect, it, vi } from "vitest";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { waitForTransportReady } from "./transport-ready.js";
describe("waitForTransportReady", () => {
beforeEach(() => {
vi.useFakeTimers();
});
afterEach(() => {
vi.useRealTimers();
});
it("returns when the check succeeds and logs after the delay", async () => {
const runtime = { log: vi.fn(), error: vi.fn(), exit: vi.fn() };
let attempts = 0;
await waitForTransportReady({
const readyPromise = waitForTransportReady({
label: "test transport",
timeoutMs: 500,
logAfterMs: 120,
@@ -20,22 +28,28 @@ describe("waitForTransportReady", () => {
return { ok: false, error: "not ready" };
},
});
for (let i = 0; i < 5; i += 1) {
await vi.advanceTimersByTimeAsync(80);
}
await readyPromise;
expect(runtime.error).toHaveBeenCalled();
});
it("throws after the timeout", async () => {
const runtime = { log: vi.fn(), error: vi.fn(), exit: vi.fn() };
await expect(
waitForTransportReady({
label: "test transport",
timeoutMs: 200,
logAfterMs: 0,
logIntervalMs: 100,
pollIntervalMs: 50,
runtime,
check: async () => ({ ok: false, error: "still down" }),
}),
).rejects.toThrow("test transport not ready");
const waitPromise = waitForTransportReady({
label: "test transport",
timeoutMs: 200,
logAfterMs: 0,
logIntervalMs: 100,
pollIntervalMs: 50,
runtime,
check: async () => ({ ok: false, error: "still down" }),
});
await vi.advanceTimersByTimeAsync(250);
await expect(waitPromise).rejects.toThrow("test transport not ready");
expect(runtime.error).toHaveBeenCalled();
});