Skip to content

Commit

Permalink
Add limit reset test
Browse files Browse the repository at this point in the history
  • Loading branch information
jsmolar committed Dec 6, 2023
1 parent db02f4b commit 191ea39
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions testsuite/tests/kuadrant/limitador/test_basic_limit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Tests that a single limit is enforced as expected over one iteration
"""
from time import sleep

import pytest

Expand All @@ -10,9 +11,9 @@
@pytest.fixture(
scope="module",
params=[
pytest.param(Limit(2, 20), id="2 requests every 20 sec"),
pytest.param(Limit(5, 15), id="5 requests every 15 sec"),
pytest.param(Limit(3, 10), id="3 request every 10 sec"),
pytest.param(Limit(2, 15), id="2 requests every 15 sec"),
pytest.param(Limit(5, 10), id="5 requests every 10 sec"),
pytest.param(Limit(3, 5), id="3 request every 5 sec"),
],
)
def limit(request):
Expand All @@ -34,3 +35,11 @@ def test_limit(client, limit):
r.status_code == 200 for r in responses
), f"Rate Limited resource unexpectedly rejected requests {responses}"
assert client.get("/get").status_code == 429


def test_limit_reset(client, limit):
"""Tests if the rate limit resets after limit duration time (1 sec is grace period)"""
responses = client.get_many("/get", limit.limit + 1)
assert responses[-1].status_code == 429
sleep(limit.duration + 1)
assert client.get("/get").status_code == 200

0 comments on commit 191ea39

Please sign in to comment.