Skip to content

Commit

Permalink
test(handler_test.go): remove unnecessary line in TestCommitLease fun…
Browse files Browse the repository at this point in the history
…ction

test(v1_keys_verifyKey.ratelimit_accuracy.test.ts): adjust upper limit calculation to be more strict
  • Loading branch information
chronark committed Sep 5, 2024
1 parent edbf56e commit 3c5c029
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func TestCommitLease(t *testing.T) {
require.NotNil(t, res.Body.Lease)

commitReq := openapi.V1RatelimitCommitLeaseRequestBody{

Cost: 5,
Lease: res.Body.Lease,
}
Expand Down
76 changes: 38 additions & 38 deletions apps/api/src/routes/v1_keys_verifyKey.ratelimit_accuracy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,43 @@ const testCases: {
rps: number;
seconds: number;
}[] = [
{
limit: 200,
duration: 10_000,
rps: 100,
seconds: 60,
},
{
limit: 10,
duration: 10000,
rps: 15,
seconds: 120,
},
{
limit: 20,
duration: 5000,
rps: 50,
seconds: 60,
},
{
limit: 200,
duration: 10000,
rps: 20,
seconds: 20,
},
{
limit: 500,
duration: 10000,
rps: 100,
seconds: 30,
},
{
limit: 100,
duration: 5000,
rps: 200,
seconds: 120,
},
];
{
limit: 200,
duration: 10_000,
rps: 100,
seconds: 60,
},
{
limit: 10,
duration: 10000,
rps: 15,
seconds: 120,
},
{
limit: 20,
duration: 5000,
rps: 50,
seconds: 60,
},
{
limit: 200,
duration: 10000,
rps: 20,
seconds: 20,
},
{
limit: 500,
duration: 10000,
rps: 100,
seconds: 30,
},
{
limit: 100,
duration: 5000,
rps: 200,
seconds: 120,
},
];

for (const { limit, duration, rps, seconds } of testCases) {
const name = `[${limit} / ${duration / 1000}s], attacked with ${rps} rps for ${seconds}s`;
Expand Down Expand Up @@ -93,7 +93,7 @@ for (const { limit, duration, rps, seconds } of testCases) {
}, 0);

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

0 comments on commit 3c5c029

Please sign in to comment.