test: speed up core runtime suites

This commit is contained in:
Peter Steinberger
2026-03-31 02:12:14 +01:00
parent f7285e0a9e
commit 6b6ddcd2a6
93 changed files with 874 additions and 980 deletions

View File

@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { importFreshModule } from "../../test/helpers/import-fresh.js";
import { CommandLane } from "./lanes.js";
@@ -56,8 +56,7 @@ function enqueueBlockedMainTask<T = void>(
}
describe("command queue", () => {
beforeEach(async () => {
vi.resetModules();
beforeAll(async () => {
({
clearCommandLane,
CommandLaneClearedError,
@@ -72,6 +71,9 @@ describe("command queue", () => {
setCommandLaneConcurrency,
waitForActiveTasks,
} = await import("./command-queue.js"));
});
beforeEach(() => {
resetCommandQueueStateForTest();
// Queue state is global across module instances, so reset main lane
// concurrency explicitly to avoid cross-file leakage.
@@ -250,9 +252,7 @@ describe("command queue", () => {
await blocker;
});
await vi.waitFor(() => {
expect(getActiveTaskCount()).toBeGreaterThanOrEqual(1);
});
expect(getActiveTaskCount()).toBeGreaterThanOrEqual(1);
// Enqueue another task — it should be stuck behind the blocker
let task2Ran = false;
@@ -260,9 +260,7 @@ describe("command queue", () => {
task2Ran = true;
});
await vi.waitFor(() => {
expect(getQueueSize(lane)).toBeGreaterThanOrEqual(2);
});
expect(getQueueSize(lane)).toBeGreaterThanOrEqual(2);
expect(task2Ran).toBe(false);
// Simulate SIGUSR1: reset all lanes. Queued work (task2) should be
@@ -396,10 +394,8 @@ describe("command queue", () => {
return "done";
});
await vi.waitFor(() => {
expect(commandQueueB.getQueueSize(lane)).toBe(1);
expect(commandQueueB.getActiveTaskCount()).toBe(1);
});
expect(commandQueueB.getQueueSize(lane)).toBe(1);
expect(commandQueueB.getActiveTaskCount()).toBe(1);
release();
await expect(task).resolves.toBe("done");