fix: finish bucket file coverage (#2968)

* fix: finish bucket file coverage

* Update packages/utils/tests/bucket.spec.ts

Co-authored-by: Jonathan Ho <heiheiho000@gmail.com>

---------

Co-authored-by: Jonathan Ho <heiheiho000@gmail.com>
This commit is contained in:
Skillz4Killz
2023-04-05 13:32:18 -05:00
committed by GitHub
co-authored by Jonathan Ho
parent f249e58c68
commit 3127531a46
+26 -1
View File
@@ -77,7 +77,7 @@ describe('bucket.ts', () => {
refillAmount: 120,
})
await bucket.acquire()
await bucket.acquire(true)
expect(bucket.remaining).to.be.equal(119)
expect(bucket.used).to.be.equal(1)
})
@@ -169,5 +169,30 @@ describe('bucket.ts', () => {
expect(bucket.remaining).equals(0)
expect(bucket.used).equals(1)
})
describe('remaining', () => {
it("should be 0 even used too many", () => {
const bucket = new LeakyBucket({
max: 1,
refillInterval: 500,
refillAmount: 1,
})
// max is < used
bucket.used = 2;
expect(bucket.remaining).equals(0);
})
})
it("Don't process queue twice", () => {
const bucket = new LeakyBucket({
max: 1,
refillInterval: 500,
refillAmount: 1,
})
// fake processing
bucket.processing = true;
// request when already processing
bucket.processQueue();
})
})
})