From dc479e36186ac9a6aee580a026073123d56a41d1 Mon Sep 17 00:00:00 2001 From: le king fu Date: Tue, 3 Nov 2026 20:02:20 -0500 Subject: [PATCH] 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 --- tests/syncSchedule.test.mjs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/syncSchedule.test.mjs b/tests/syncSchedule.test.mjs index 1d78954..14e91df 100644 --- a/tests/syncSchedule.test.mjs +++ b/tests/syncSchedule.test.mjs @@ -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;