perf(test): trim duplicate gateway and auto-reply test overhead

This commit is contained in:
Peter Steinberger
2026-02-13 23:40:25 +00:00
parent ad57e561c6
commit 5caf829d28
6 changed files with 34 additions and 234 deletions

View File

@@ -112,8 +112,6 @@ describe("command queue", () => {
await blocker;
});
// Give the event loop a tick for the task to start.
await new Promise((r) => setTimeout(r, 5));
expect(getActiveTaskCount()).toBe(1);
resolve1();
@@ -136,18 +134,21 @@ describe("command queue", () => {
await blocker;
});
// Give the task a tick to start.
await new Promise((r) => setTimeout(r, 5));
vi.useFakeTimers();
try {
const drainPromise = waitForActiveTasks(5000);
const drainPromise = waitForActiveTasks(5000);
// Resolve the blocker after a short delay.
setTimeout(() => resolve1(), 10);
await vi.advanceTimersByTimeAsync(100);
// Resolve the blocker after a short delay.
setTimeout(() => resolve1(), 50);
const { drained } = await drainPromise;
expect(drained).toBe(true);
const { drained } = await drainPromise;
expect(drained).toBe(true);
await task;
await task;
} finally {
vi.useRealTimers();
}
});
it("waitForActiveTasks returns drained=false on timeout", async () => {
@@ -160,13 +161,18 @@ describe("command queue", () => {
await blocker;
});
await new Promise((r) => setTimeout(r, 5));
vi.useFakeTimers();
try {
const waitPromise = waitForActiveTasks(50);
await vi.advanceTimersByTimeAsync(100);
const { drained } = await waitPromise;
expect(drained).toBe(false);
const { drained } = await waitForActiveTasks(50);
expect(drained).toBe(false);
resolve1();
await task;
resolve1();
await task;
} finally {
vi.useRealTimers();
}
});
it("resetAllLanes drains queued work immediately after reset", async () => {
@@ -228,15 +234,12 @@ describe("command queue", () => {
const first = enqueueCommandInLane(lane, async () => {
await blocker1;
});
await new Promise((r) => setTimeout(r, 5));
const drainPromise = waitForActiveTasks(2000);
// Starts after waitForActiveTasks snapshot and should not block drain completion.
const second = enqueueCommandInLane(lane, async () => {
await blocker2;
});
await new Promise((r) => setTimeout(r, 5));
expect(getActiveTaskCount()).toBeGreaterThanOrEqual(2);
resolve1();
@@ -262,9 +265,6 @@ describe("command queue", () => {
// Second task is queued behind the first.
const second = enqueueCommand(async () => "second");
// Give the first task a tick to start.
await new Promise((r) => setTimeout(r, 5));
const removed = clearCommandLane();
expect(removed).toBe(1); // only the queued (not active) entry