feat(gateway): add configurable lane queue mode, cap, and overflow

This commit is contained in:
William Valentin
2026-02-16 11:48:45 -08:00
parent 527602fd8a
commit f7284a4ef1
9 changed files with 178 additions and 5 deletions
+57
View File
@@ -191,4 +191,61 @@ describe('LaneQueue', () => {
const r2 = await queue.enqueue('lane-a', async () => 'second');
expect(r2).toBe('second');
});
it('steer mode keeps only the most recent pending request', async () => {
const queue = new LaneQueue({ mode: 'steer' });
let resolveFirst!: () => void;
const firstBlocks = new Promise<void>((r) => { resolveFirst = r; });
const p1 = queue.enqueue('lane-a', async () => {
await firstBlocks;
return 'active';
});
const p2 = queue.enqueue('lane-a', async () => 'old-pending');
const p3 = queue.enqueue('lane-a', async () => 'latest-pending');
await expect(p2).rejects.toThrow('Superseded by newer request');
resolveFirst();
await expect(p1).resolves.toBe('active');
await expect(p3).resolves.toBe('latest-pending');
});
it('drop_new overflow rejects newest request when cap is reached', async () => {
const queue = new LaneQueue({ cap: 1, overflow: 'drop_new' });
let resolveFirst!: () => void;
const firstBlocks = new Promise<void>((r) => { resolveFirst = r; });
const p1 = queue.enqueue('lane-a', async () => {
await firstBlocks;
return 'active';
});
const p2 = queue.enqueue('lane-a', async () => 'pending-1');
const p3 = queue.enqueue('lane-a', async () => 'pending-2');
await expect(p3).rejects.toThrow('Lane queue full (drop_new)');
resolveFirst();
await expect(p1).resolves.toBe('active');
await expect(p2).resolves.toBe('pending-1');
});
it('drop_old overflow evicts oldest pending request when cap is reached', async () => {
const queue = new LaneQueue({ cap: 1, overflow: 'drop_old' });
let resolveFirst!: () => void;
const firstBlocks = new Promise<void>((r) => { resolveFirst = r; });
const p1 = queue.enqueue('lane-a', async () => {
await firstBlocks;
return 'active';
});
const p2 = queue.enqueue('lane-a', async () => 'old-pending');
const p3 = queue.enqueue('lane-a', async () => 'new-pending');
await expect(p2).rejects.toThrow('Lane queue overflow (drop_old)');
resolveFirst();
await expect(p1).resolves.toBe('active');
await expect(p3).resolves.toBe('new-pending');
});
});