diff --git a/tests/suite/test_virtual_server_service_insight.py b/tests/suite/test_virtual_server_service_insight.py index 82029eaa67..bbda23c107 100644 --- a/tests/suite/test_virtual_server_service_insight.py +++ b/tests/suite/test_virtual_server_service_insight.py @@ -1,3 +1,5 @@ +from unittest import mock + import pytest import requests from settings import TEST_DATA @@ -28,11 +30,19 @@ def test_responses_svc_insight_http( self, request, kube_apis, crd_ingress_controller, virtual_server_setup, ingress_controller_endpoint ): """test responses from service insight endpoint with http""" + retry = 0 + resp = mock.Mock() + resp.json.return_value = {} + resp.status_code == 502 vs_source = f"{TEST_DATA}/virtual-server/standard/virtual-server.yaml" host = get_first_host_from_yaml(vs_source) req_url = f"http://{ingress_controller_endpoint.public_ip}:{ingress_controller_endpoint.service_insight_port}/probe/{host}" ensure_response_from_backend(req_url, virtual_server_setup.vs_host) - resp = requests.get(req_url) + while (resp.json() != {"Total": 3, "Up": 3, "Unhealthy": 0}) and retry < 5: + resp = requests.get(req_url) + wait_before_test() + retry = +1 + assert resp.status_code == 200, f"Expected 200 code for /probe/{host} but got {resp.status_code}" assert resp.json() == {"Total": 3, "Up": 3, "Unhealthy": 0} @@ -78,11 +88,18 @@ def test_responses_svc_insight_https( virtual_server_setup, ): """test responses from service insight endpoint with https""" + retry = 0 + resp = mock.Mock() + resp.json.return_value = {} + resp.status_code == 502 vs_source = f"{TEST_DATA}/virtual-server/standard/virtual-server.yaml" host = get_first_host_from_yaml(vs_source) req_url = f"https://{ingress_controller_endpoint.public_ip}:{ingress_controller_endpoint.service_insight_port}/probe/{host}" ensure_response_from_backend(req_url, virtual_server_setup.vs_host) - resp = requests.get(req_url, verify=False) + while (resp.json() != {"Total": 3, "Up": 3, "Unhealthy": 0}) and retry < 5: + resp = requests.get(req_url, verify=False) + wait_before_test() + retry = +1 assert resp.status_code == 200, f"Expected 200 code for /probe/{host} but got {resp.status_code}" assert resp.json() == {"Total": 3, "Up": 3, "Unhealthy": 0} @@ -96,6 +113,11 @@ def test_responses_svc_insight_update_pods( crd_ingress_controller, virtual_server_setup, ): + """test responses from service insight endpoint with https and update number of replicas""" + retry = 0 + resp = mock.Mock() + resp.json.return_value = {} + resp.status_code == 502 vs_source = f"{TEST_DATA}/virtual-server/standard/virtual-server.yaml" host = get_first_host_from_yaml(vs_source) req_url = f"https://{ingress_controller_endpoint.public_ip}:{ingress_controller_endpoint.service_insight_port}/probe/{host}" @@ -104,7 +126,9 @@ def test_responses_svc_insight_update_pods( # patch backend1 deployment with 5 replicas patch_deployment_from_yaml(kube_apis.apps_v1_api, test_namespace, f"{TEST_DATA}/service-insight/app.yaml") ensure_response_from_backend(req_url, virtual_server_setup.vs_host) - wait_before_test(15) - resp = requests.get(req_url, verify=False) + while (resp.json() != {"Total": 6, "Up": 6, "Unhealthy": 0}) and retry < 5: + resp = requests.get(req_url, verify=False) + wait_before_test() + retry = +1 assert resp.status_code == 200, f"Expected 200 code for /probe/{host} but got {resp.status_code}" assert resp.json() == {"Total": 6, "Up": 6, "Unhealthy": 0}