mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
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:
co-authored by
Jonathan Ho
parent
f249e58c68
commit
3127531a46
@@ -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();
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user