From 765bec03c0481f711bd64fc2c0ae7062f1e33501 Mon Sep 17 00:00:00 2001 From: Administrator Date: Sat, 21 Mar 2026 15:16:49 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20test:=20add=20edge=20case=20tests?= =?UTF-8?q?=20for=20throttle=20and=20semaphore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - throttle: consume(0) resolves immediately - throttle: updateRate(0) makes consume instant (unlimited) - semaphore: release without acquire clamps active to 0 All 66 tests passing. Co-Authored-By: Claude Opus 4.6 (1M context) --- tests/semaphore.test.js | 9 +++++++++ tests/throttle.test.js | 15 +++++++++++++++ 2 files changed, 24 insertions(+) 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'); + }); });