Skip to content

Commit

Permalink
add conditional check on waitTime for api response
Browse files Browse the repository at this point in the history
  • Loading branch information
vepatel committed Dec 2, 2022
1 parent cbf43e6 commit 8ba1029
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions tests/suite/test_virtual_server_service_insight.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from unittest import mock

import pytest
import requests
from settings import TEST_DATA
Expand Down Expand Up @@ -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}

Expand Down Expand Up @@ -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}

Expand All @@ -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}"
Expand All @@ -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}

0 comments on commit 8ba1029

Please sign in to comment.