Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+12
-6
@@ -41,6 +41,16 @@ describe("createFixedWindowRateLimiter", () => {
|
||||
await store.close();
|
||||
});
|
||||
|
||||
test("reserves a weighted batch in one atomic decision", async () => {
|
||||
const { limiter, store } = buildLimiter({ max: 10 });
|
||||
const first = await limiter.consume("batch", 7);
|
||||
expect(first).toMatchObject({ allowed: true, remaining: 3 });
|
||||
const overflow = await limiter.consume("batch", 4);
|
||||
expect(overflow).toMatchObject({ allowed: false, remaining: 0 });
|
||||
await expect(limiter.consume("batch", 0)).rejects.toThrow(/weight/);
|
||||
await store.close();
|
||||
});
|
||||
|
||||
test("resets after the window expires", async () => {
|
||||
let now = 1_000;
|
||||
const { limiter, store } = buildLimiter({ windowSeconds: 1, max: 1, now: () => now });
|
||||
@@ -63,12 +73,8 @@ describe("createFixedWindowRateLimiter", () => {
|
||||
test("rejects invalid configuration", () => {
|
||||
const adapter = new MemoryAdapter();
|
||||
const store = createSharedStore({ namespace: "ratelimit", adapter });
|
||||
expect(() =>
|
||||
createFixedWindowRateLimiter({ store, prefix: "x", windowSeconds: 0, max: 1 }),
|
||||
).toThrow(/windowSeconds/);
|
||||
expect(() =>
|
||||
createFixedWindowRateLimiter({ store, prefix: "x", windowSeconds: 1, max: 0 }),
|
||||
).toThrow(/max/);
|
||||
expect(() => createFixedWindowRateLimiter({ store, prefix: "x", windowSeconds: 0, max: 1 })).toThrow(/windowSeconds/);
|
||||
expect(() => createFixedWindowRateLimiter({ store, prefix: "x", windowSeconds: 1, max: 0 })).toThrow(/max/);
|
||||
});
|
||||
|
||||
test("reports a sensible resetAt", async () => {
|
||||
|
||||
Reference in new issue
Block a user