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;