diff --git a/tests/semaphore.test.js b/tests/semaphore.test.js index 3763ac0..91cb77f 100644 --- a/tests/semaphore.test.js +++ b/tests/semaphore.test.js @@ -162,4 +162,13 @@ describe('Semaphore', () => { await new Promise(r => setTimeout(r, 5)); assert.equal(sem.pending, 1); }); + + it('release without acquire clamps active to 0', () => { + const sem = new Semaphore(2); + assert.equal(sem.active, 0); + sem.release(); + assert.equal(sem.active, 0, 'should not go negative'); + sem.release(); + assert.equal(sem.active, 0, 'should still be 0'); + }); }); diff --git a/tests/throttle.test.js b/tests/throttle.test.js index b692058..2b74b3b 100644 --- a/tests/throttle.test.js +++ b/tests/throttle.test.js @@ -83,4 +83,19 @@ describe('Throttle', () => { const elapsed = Date.now() - start2; assert.ok(elapsed >= 150, `third consume should wait for refill, took ${elapsed}ms`); }); + + it('consume(0) resolves immediately', async () => { + const t = new Throttle(100); + const start = Date.now(); + await t.consume(0); + assert.ok(Date.now() - start < 50); + }); + + it('updateRate to unlimited (0) makes consume instant', async () => { + const t = new Throttle(100); // very slow + t.updateRate(0); // unlimited + const start = Date.now(); + await t.consume(1_000_000); + assert.ok(Date.now() - start < 50, 'unlimited rate should be instant'); + }); });