✅ test: add edge case tests for throttle and semaphore
- 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) <noreply@anthropic.com>
This commit is contained in:
parent
a56594b1df
commit
765bec03c0
@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user