Skip to content

Commit 97e9438

Browse files
committed
test: rateLimiter.cubicThrottle
1 parent 9ffd6c1 commit 97e9438

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

packages/middleware-retry/src/DefaultRateLimiter.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,27 @@ describe(DefaultRateLimiter.name, () => {
3636
});
3737
});
3838

39+
describe("cubicThrottle", () => {
40+
it.each([
41+
[5, 0.112],
42+
[6, 0.09333333],
43+
[7, 0.08],
44+
[8, 0.07],
45+
[9, 0.06222222],
46+
])("timestamp: %d, calculatedRate: %d", (timestamp, calculatedRate) => {
47+
jest.spyOn(Date, "now").mockImplementation(() => 0);
48+
const rateLimiter = new DefaultRateLimiter();
49+
rateLimiter["lastMaxRate"] = 10;
50+
rateLimiter["lastThrottleTime"] = 5;
51+
52+
(isThrottlingError as jest.Mock).mockReturnValueOnce(true);
53+
jest.spyOn(Date, "now").mockImplementation(() => timestamp * 1000);
54+
const cubicThrottleSpy = jest.spyOn(DefaultRateLimiter.prototype as any, "cubicThrottle");
55+
rateLimiter.updateClientSendingRate({});
56+
expect(cubicThrottleSpy).toHaveLastReturnedWith(calculatedRate);
57+
});
58+
});
59+
3960
it("updateClientSendingRate", () => {
4061
jest.spyOn(Date, "now").mockImplementation(() => 0);
4162
const rateLimiter = new DefaultRateLimiter();

0 commit comments

Comments
 (0)