test(sync): pin the two-place rule of the scheduler

A single free place with a queued backlog starts no run until a second
place frees up; the condition alone was not pinned by the latency test.

Refs #178

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
le king fu 2026-11-03 20:02:20 -05:00
commit dc479e3618

View file

@ -225,6 +225,22 @@ test('with 300 ms per request, a 9-batch queue empties in bounded time and no ru
assert.ok(maxInAnyWindow(server.requests) <= REQUEST_BUDGET, `max ${maxInAnyWindow(server.requests)} in a window`);
});
test('with a single free place, no run starts until a second one frees up', async () => {
const clock = fakeClock();
const server = fakeServer(clock, { batches: 1 });
const s = createSyncScheduler({ now: clock.now, setTimer: clock.setTimer, run: server.run });
s.tracker.request();
await clock.advance(1000);
for (let i = 1; i < REQUEST_BUDGET - 1; i++) s.tracker.request();
s.request();
await clock.advance(BUDGET_WINDOW_MS - 1001);
assert.equal(server.runs, 0, 'one place left: a run would only pull');
await clock.advance(1);
assert.equal(server.runs, 1, 'the run starts once the oldest request leaves the window');
assert.equal(server.emptyPushRuns, 0);
assert.equal(server.queue, 0);
});
test('after a 429 with Retry-After: 20, no request before 20 s', async () => {
const clock = fakeClock();
let first = true;