Tests: stabilize shard-2 queue and channel state

This commit is contained in:
Vignesh Natarajan
2026-03-28 23:33:49 -07:00
committed by Vignesh
parent 9c185faba9
commit 4d54376483
2 changed files with 15 additions and 1 deletions

View File

@@ -29,6 +29,7 @@ let getActiveTaskCount: CommandQueueModule["getActiveTaskCount"];
let getQueueSize: CommandQueueModule["getQueueSize"];
let markGatewayDraining: CommandQueueModule["markGatewayDraining"];
let resetAllLanes: CommandQueueModule["resetAllLanes"];
let resetCommandQueueStateForTest: CommandQueueModule["resetCommandQueueStateForTest"];
let setCommandLaneConcurrency: CommandQueueModule["setCommandLaneConcurrency"];
let waitForActiveTasks: CommandQueueModule["waitForActiveTasks"];
@@ -67,10 +68,11 @@ describe("command queue", () => {
getQueueSize,
markGatewayDraining,
resetAllLanes,
resetCommandQueueStateForTest,
setCommandLaneConcurrency,
waitForActiveTasks,
} = await import("./command-queue.js"));
resetAllLanes();
resetCommandQueueStateForTest();
// Queue state is global across module instances, so reset main lane
// concurrency explicitly to avoid cross-file leakage.
setCommandLaneConcurrency(CommandLane.Main, 1);

View File

@@ -254,6 +254,18 @@ export function clearCommandLane(lane: string = CommandLane.Main) {
return removed;
}
/**
* Test-only hard reset that discards all queue state, including preserved
* queued work from previous generations. Use this when a suite needs an
* isolated baseline across shared-worker runs.
*/
export function resetCommandQueueStateForTest(): void {
const queueState = getQueueState();
queueState.gatewayDraining = false;
queueState.lanes.clear();
queueState.nextTaskId = 1;
}
/**
* Reset all lane runtime state to idle. Used after SIGUSR1 in-process
* restarts where interrupted tasks' finally blocks may not run, leaving