Skip to content

Commit

Permalink
test: improve accuracy of lower limit calculation in rate limit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chronark committed Sep 19, 2024
1 parent a43b948 commit 5036426
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ for (const { limit, duration, rps, seconds } of testCases) {

const exactLimit = Math.min(results.length, (limit / (duration / 1000)) * seconds);
const upperLimit = Math.round(exactLimit * 2.5);
const lowerLimit = exactLimit * 0.95;
const lowerLimit = Math.round(exactLimit * 0.95);
console.info({ name, passed, exactLimit, upperLimit, lowerLimit });
t.expect(passed).toBeGreaterThanOrEqual(lowerLimit);
t.expect(passed).toBeLessThanOrEqual(upperLimit);
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/v1_ratelimit_limit.accuracy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ for (const { limit, duration, rps, seconds } of testCases) {

const exactLimit = Math.min(results.length, (limit / (duration / 1000)) * seconds);
const upperLimit = Math.round(exactLimit * 1.5);
const lowerLimit = exactLimit * 0.95;
const lowerLimit = Math.round(exactLimit * 0.95);
console.info({ name, passed, exactLimit, upperLimit, lowerLimit });
t.expect(passed).toBeGreaterThanOrEqual(lowerLimit);
t.expect(passed).toBeLessThanOrEqual(upperLimit);
Expand Down

0 comments on commit 5036426

Please sign in to comment.