From efdd31fb9993203295a6804db7e470652dd93c12 Mon Sep 17 00:00:00 2001 From: tellet Date: Wed, 20 Nov 2019 09:37:25 +0000 Subject: [PATCH] Improve flaky tests --- tests/suite/resources_utils.py | 16 ++++++++++------ tests/suite/test_v_s_route.py | 1 + tests/suite/test_v_s_route_upstream_options.py | 2 +- tests/suite/test_v_s_route_upstream_tls.py | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/tests/suite/resources_utils.py b/tests/suite/resources_utils.py index d54b85c828..320bf27638 100644 --- a/tests/suite/resources_utils.py +++ b/tests/suite/resources_utils.py @@ -9,6 +9,8 @@ from kubernetes.client.rest import ApiException from kubernetes.stream import stream from kubernetes import client +from more_itertools import first + from settings import TEST_DATA, RECONFIGURATION_DELAY, DEPLOYMENTS @@ -297,14 +299,16 @@ def wait_for_public_ip(v1: CoreV1Api, namespace: str) -> str: """ resp = v1.list_namespaced_service(namespace) counter = 0 - while str(resp.items[0].status.load_balancer.ingress) == "None" and counter < 20: + svc_item = first(x for x in resp.items if x.metadata.name == "nginx-ingress") + while str(svc_item.status.load_balancer.ingress) == "None" and counter < 20: time.sleep(5) resp = v1.list_namespaced_service(namespace) + svc_item = first(x for x in resp.items if x.metadata.name == "nginx-ingress") counter = counter + 1 if counter == 20: pytest.fail("After 100 seconds the LB still doesn't have a Public IP. Exiting...") - print(f"Public IP ='{resp.items[0].status.load_balancer.ingress[0].ip}'") - return str(resp.items[0].status.load_balancer.ingress[0].ip) + print(f"Public IP ='{svc_item.status.load_balancer.ingress[0].ip}'") + return str(svc_item.status.load_balancer.ingress[0].ip) def create_secret_from_yaml(v1: CoreV1Api, namespace, yaml_manifest) -> str: @@ -983,8 +987,8 @@ def ensure_response_from_backend(req_url, host) -> None: """ for _ in range(30): resp = requests.get(req_url, headers={"host": host}, verify=False) - if resp.status_code != 502: - print(f"At last after {_ * 2} seconds got 200. Continue...") + if resp.status_code != 502 and resp.status_code != 504: + print(f"After {_ * 2} seconds got non 502|504 response. Continue with tests...") return time.sleep(2) - pytest.fail(f"Keep getting 502 from {req_url} after 60 seconds. Exiting...") + pytest.fail(f"Keep getting 502|504 from {req_url} after 60 seconds. Exiting...") diff --git a/tests/suite/test_v_s_route.py b/tests/suite/test_v_s_route.py index 4b1f93e237..feba6694c8 100644 --- a/tests/suite/test_v_s_route.py +++ b/tests/suite/test_v_s_route.py @@ -32,6 +32,7 @@ def assert_locations_not_in_config(config, paths): @pytest.mark.smoke +@pytest.mark.vsr @pytest.mark.parametrize('crd_ingress_controller, v_s_route_setup', [({"type": "complete", "extra_args": [f"-enable-custom-resources"]}, {"example": "virtual-server-route"})], diff --git a/tests/suite/test_v_s_route_upstream_options.py b/tests/suite/test_v_s_route_upstream_options.py index c2925e4432..56b738d689 100644 --- a/tests/suite/test_v_s_route_upstream_options.py +++ b/tests/suite/test_v_s_route_upstream_options.py @@ -220,7 +220,7 @@ def test_v_s_r_overrides_config_map(self, kube_apis, replace_configmap_from_yaml(kube_apis.v1, config_map_name, ingress_controller_prerequisites.namespace, f"{TEST_DATA}/virtual-server-route-upstream-options/configmap-with-keys.yaml") - wait_before_test(1) + wait_before_test(2) ic_pod_name = get_first_pod_name(kube_apis.v1, ingress_controller_prerequisites.namespace) config = get_vs_nginx_template_conf(kube_apis.v1, v_s_route_setup.namespace, diff --git a/tests/suite/test_v_s_route_upstream_tls.py b/tests/suite/test_v_s_route_upstream_tls.py index 9e23466688..0284bfedbb 100644 --- a/tests/suite/test_v_s_route_upstream_tls.py +++ b/tests/suite/test_v_s_route_upstream_tls.py @@ -49,7 +49,7 @@ def fin(): [({"type": "complete", "extra_args": [f"-enable-custom-resources"]}, {"example": "virtual-server-route-upstream-tls"})], indirect=True) -class TestVSRouteUpstreamOptions: +class TestVSRouteUpstreamTls: def test_responses_and_config_after_setup(self, kube_apis, ingress_controller_prerequisites, crd_ingress_controller, v_s_route_setup, v_s_route_secure_app_setup): ic_pod_name = get_first_pod_name(kube_apis.v1, ingress_controller_prerequisites.namespace)