From 3016792033264a32376cebdd772a0bb8501fad75 Mon Sep 17 00:00:00 2001 From: averevki Date: Fri, 25 Oct 2024 16:14:50 +0200 Subject: [PATCH] Improve scale gateway listeners test Signed-off-by: averevki --- testsuite/kuadrant/policy/__init__.py | 18 +++++++++++++++ .../gateway/test_scale_listeners.py | 23 +++++++++---------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/testsuite/kuadrant/policy/__init__.py b/testsuite/kuadrant/policy/__init__.py index 207e9002..0e3f7aa9 100644 --- a/testsuite/kuadrant/policy/__init__.py +++ b/testsuite/kuadrant/policy/__init__.py @@ -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""" diff --git a/testsuite/tests/singlecluster/gateway/test_scale_listeners.py b/testsuite/tests/singlecluster/gateway/test_scale_listeners.py index 8392e4ad..94c0d052 100644 --- a/testsuite/tests/singlecluster/gateway/test_scale_listeners.py +++ b/testsuite/tests/singlecluster/gateway/test_scale_listeners.py @@ -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] @@ -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() @@ -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() @@ -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