From 191ea390c05a82c3d9737e13a1157369865e9708 Mon Sep 17 00:00:00 2001 From: Jakub Smolar Date: Wed, 6 Dec 2023 15:19:04 +0100 Subject: [PATCH] Add limit reset test --- .../tests/kuadrant/limitador/test_basic_limit.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/testsuite/tests/kuadrant/limitador/test_basic_limit.py b/testsuite/tests/kuadrant/limitador/test_basic_limit.py index d9da022a9..f37aec29a 100644 --- a/testsuite/tests/kuadrant/limitador/test_basic_limit.py +++ b/testsuite/tests/kuadrant/limitador/test_basic_limit.py @@ -1,6 +1,7 @@ """ Tests that a single limit is enforced as expected over one iteration """ +from time import sleep import pytest @@ -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): @@ -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