Skip to content

Commit

Permalink
Merge pull request Kuadrant#567 from averevki/improve-scale-listeners
Browse files Browse the repository at this point in the history
Improve scale gateway listeners test
  • Loading branch information
jsmolar authored Nov 8, 2024
2 parents 9c6f248 + 3016792 commit e93b295
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
18 changes: 18 additions & 0 deletions testsuite/kuadrant/policy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ def _check(obj):
return _check


def is_affected_by(policy: "Policy"):
"""Returns function, that returns True if the Kubernetes object has 'affected by policy' condition"""

def _check(obj):
for condition in obj.model.status.conditions:
if check_condition(
condition,
f"kuadrant.io/{policy.kind(lowercase=False)}Affected",
"True",
"Accepted",
f"Object affected by {policy.kind(lowercase=False)} {policy.namespace()}/{policy.name()}",
):
return True
return False

return _check


class Policy(KubernetesObject):
"""Base class with common functionality for all policies"""

Expand Down
23 changes: 11 additions & 12 deletions testsuite/tests/singlecluster/gateway/test_scale_listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from testsuite.httpx import KuadrantClient
from testsuite.gateway.gateway_api.route import HTTPRoute
from testsuite.gateway.gateway_api.gateway import KuadrantGateway, GatewayListener
from testsuite.kuadrant.policy import is_affected_by
from testsuite.kuadrant.policy.dns import DNSPolicy

pytestmark = [pytest.mark.kuadrant_only, pytest.mark.dnspolicy]
Expand All @@ -16,8 +17,7 @@
def gateway(request, cluster, blame, base_domain, module_label):
"""Create first gateway with 64 listeners"""
gw = KuadrantGateway.create_instance(cluster, blame("gw"), {"app": module_label})
gw.add_listener(GatewayListener(hostname=f"gw1-api.{base_domain}"))
for i in range(1, MAX_GATEWAY_LISTENERS):
for i in range(1, MAX_GATEWAY_LISTENERS + 1):
gw.add_listener(GatewayListener(name=f"api{i}", hostname=f"gw1-api{i}.{base_domain}"))
request.addfinalizer(gw.delete)
gw.commit()
Expand All @@ -29,8 +29,7 @@ def gateway(request, cluster, blame, base_domain, module_label):
def gateway2(request, cluster, blame, base_domain, module_label):
"""Create second gateway with 64 listeners"""
gw = KuadrantGateway.create_instance(cluster, blame("gw"), {"app": module_label})
gw.add_listener(GatewayListener(hostname=f"gw2-api.{base_domain}"))
for i in range(1, MAX_GATEWAY_LISTENERS):
for i in range(1, MAX_GATEWAY_LISTENERS + 1):
gw.add_listener(GatewayListener(name=f"api{i}", hostname=f"gw2-api{i}.{base_domain}"))
request.addfinalizer(gw.delete)
gw.commit()
Expand Down Expand Up @@ -68,11 +67,11 @@ def commit(request, routes, dns_policy, dns_policy2): # pylint: disable=unused-

def test_gateway_max_listeners(gateway, gateway2, dns_policy, dns_policy2, base_domain):
"""Verify that both gateways are affected by DNSPolicy and their listeners are reachable"""
assert gateway.refresh().is_affected_by(dns_policy)
assert gateway2.refresh().is_affected_by(dns_policy2)

assert KuadrantClient(base_url=f"http://gw1-api.{base_domain}").get("/get").response.status_code == 200
assert KuadrantClient(base_url=f"http://gw1-api63.{base_domain}").get("/get").response.status_code == 200

assert KuadrantClient(base_url=f"http://gw2-api21.{base_domain}").get("/get").response.status_code == 200
assert KuadrantClient(base_url=f"http://gw2-api53.{base_domain}").get("/get").response.status_code == 200
assert gateway.wait_until(is_affected_by(dns_policy))
assert gateway2.wait_until(is_affected_by(dns_policy2))

for i in [1, 2]:
for j in range(1, MAX_GATEWAY_LISTENERS + 1):
res = KuadrantClient(base_url=f"http://gw{i}-api{j}.{base_domain}").get("/get").response
assert res is not None
assert res.status_code == 200

0 comments on commit e93b295

Please sign in to comment.