-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add section targeting tests for ratelimit policy #634
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"""Conftest for RLP section_name targeting tests""" | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def route(route, backend): | ||
"""Add two backend rules for different paths to the route""" | ||
route.remove_all_rules() | ||
route.add_backend(backend, "/get") | ||
route.add_backend(backend, "/anything") | ||
return route | ||
|
||
|
||
@pytest.fixture(scope="module", autouse=True) | ||
def commit(request, route, rate_limit): # pylint: disable=unused-argument | ||
"""Commits RateLimitPolicy after the HTTPRoute is created""" | ||
request.addfinalizer(rate_limit.delete) | ||
rate_limit.commit() | ||
rate_limit.wait_for_ready() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""Tests that the RLP is correctly applies to the chosen Gateway Listener""" | ||
|
||
import pytest | ||
|
||
from testsuite.kuadrant.policy.rate_limit import Limit, RateLimitPolicy | ||
|
||
pytestmark = [pytest.mark.kuadrant_only, pytest.mark.limitador] | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def rate_limit(cluster, blame, module_label, gateway): | ||
"""Add a RateLimitPolicy targeting the specific Gateway Listener""" | ||
rlp = RateLimitPolicy.create_instance(cluster, blame("limit"), gateway, "api", labels={"testRun": module_label}) | ||
rlp.add_limit("basic", [Limit(2, "10s")]) | ||
return rlp | ||
|
||
|
||
def test_limit_match_gateway_listener(client): | ||
"""Tests that RLP correctly applies to the specific Gateway Listener""" | ||
responses = client.get_many("/get", 2) | ||
responses.assert_all(status_code=200) | ||
|
||
assert client.get("/get").status_code == 429 | ||
assert client.get("/anything").status_code == 429 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"""Test multiple RLP's targeting different HTTPRoute Rules do not interfere with each other""" | ||
|
||
import pytest | ||
|
||
from testsuite.kuadrant.policy.rate_limit import Limit, RateLimitPolicy | ||
|
||
|
||
pytestmark = [pytest.mark.kuadrant_only, pytest.mark.limitador] | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def rate_limit(cluster, blame, module_label, route): | ||
"""Add a RateLimitPolicy targeting the first HTTPRoute Rule""" | ||
rate_limit = RateLimitPolicy.create_instance( | ||
cluster, blame("limit"), route, "rule-1", labels={"testRun": module_label} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Section of HTTPRoute is the single rule. As far as I understand, rule name is based on the rule position in the route rules list |
||
) | ||
rate_limit.add_limit("basic", [Limit(3, "5s")]) | ||
return rate_limit | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def rate_limit2(cluster, blame, module_label, route): | ||
"""Add a RateLimitPolicy targeting the second HTTPRoute Rule""" | ||
rlp = RateLimitPolicy.create_instance(cluster, blame("limit"), route, "rule-2", labels={"testRun": module_label}) | ||
rlp.add_limit("basic", [Limit(2, "5s")]) | ||
return rlp | ||
|
||
|
||
@pytest.fixture(scope="module", autouse=True) | ||
def commit(request, rate_limit, rate_limit2): | ||
"""Commit and wait for RateLimitPolicies to be fully enforced""" | ||
for policy in [rate_limit, rate_limit2]: | ||
request.addfinalizer(policy.delete) | ||
policy.commit() | ||
policy.wait_for_ready() | ||
|
||
|
||
def test_multiple_limits_targeting_different_route_rules(client): | ||
"""Test targeting separate HTTPRoute Rules with different limits""" | ||
responses = client.get_many("/get", 3) | ||
responses.assert_all(status_code=200) | ||
assert client.get("/get").status_code == 429 | ||
|
||
responses = client.get_many("/anything", 2) | ||
responses.assert_all(status_code=200) | ||
assert client.get("/anything").status_code == 429 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"""Test that multiple limits targeting same Gateway Listener are correctly applied""" | ||
|
||
import pytest | ||
|
||
from testsuite.kuadrant.policy.rate_limit import Limit, RateLimitPolicy | ||
|
||
|
||
pytestmark = [pytest.mark.kuadrant_only, pytest.mark.limitador] | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def rate_limit(cluster, blame, module_label, gateway): | ||
"""Add a RateLimitPolicy targeting the Gateway Listener with two limits""" | ||
rate_limit = RateLimitPolicy.create_instance( | ||
cluster, blame("limit"), gateway, "api", labels={"testRun": module_label} | ||
) | ||
rate_limit.add_limit("test1", [Limit(8, "10s")]) | ||
rate_limit.add_limit("test2", [Limit(3, "5s")]) | ||
return rate_limit | ||
|
||
|
||
def test_two_limits_targeting_one_gateway_listener(client): | ||
"""Test that one limit ends up shadowing others""" | ||
responses = client.get_many("/get", 3) | ||
responses.assert_all(status_code=200) | ||
assert client.get("/get").status_code == 429 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"""Test that multiple limits targeting same rule are correctly applied""" | ||
|
||
import pytest | ||
|
||
from testsuite.kuadrant.policy.rate_limit import Limit, RateLimitPolicy | ||
|
||
|
||
pytestmark = [pytest.mark.kuadrant_only, pytest.mark.limitador] | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def rate_limit(cluster, blame, module_label, route): | ||
"""Add a RateLimitPolicy targeting the first HTTPRoute Rule with two limits""" | ||
rate_limit = RateLimitPolicy.create_instance( | ||
cluster, blame("limit"), route, "rule-1", labels={"testRun": module_label} | ||
) | ||
rate_limit.add_limit("test1", [Limit(8, "10s")]) | ||
rate_limit.add_limit("test2", [Limit(3, "5s")]) | ||
return rate_limit | ||
|
||
|
||
def test_two_limits_targeting_one_route_rule(client): | ||
"""Test that one limit ends up shadowing others""" | ||
responses = client.get_many("/get", 3) | ||
responses.assert_all(status_code=200) | ||
assert client.get("/get").status_code == 429 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""Tests that the RLP is correctly applied to the specific route rule""" | ||
|
||
import pytest | ||
|
||
from testsuite.kuadrant.policy.rate_limit import Limit, RateLimitPolicy | ||
|
||
pytestmark = [pytest.mark.kuadrant_only, pytest.mark.limitador] | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def rate_limit(cluster, blame, module_label, route): | ||
"""Add a RateLimitPolicy targeting the first HTTPRoute Rule.""" | ||
rlp = RateLimitPolicy.create_instance(cluster, blame("limit"), route, "rule-1", labels={"testRun": module_label}) | ||
rlp.add_limit("basic", [Limit(2, "10s")]) | ||
return rlp | ||
|
||
|
||
def test_limit_match_route_rule(client): | ||
"""Tests that RLP correctly applies to the specific HTTPRoute Rule""" | ||
responses = client.get_many("/get", 2) | ||
responses.assert_all(status_code=200) | ||
assert client.get("/get").status_code == 429 | ||
|
||
response = client.get("/anything") | ||
assert response.status_code == 200 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use
GatewayListener.name
if referencing the default name for listenerapi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better for the section name to be explicitly written here