diff --git a/testsuite/httpx/__init__.py b/testsuite/httpx/__init__.py index 025223c8..2ba4a9f5 100644 --- a/testsuite/httpx/__init__.py +++ b/testsuite/httpx/__init__.py @@ -3,7 +3,7 @@ from typing import Union import backoff -from httpx import Client, Response +from httpx import Client, Response, ConnectError from testsuite.certificates import Certificate @@ -19,7 +19,7 @@ def create_tmp_file(content: str): class UnexpectedResponse(Exception): - """Slightly different response attributes were expected""" + """Slightly different response attributes were expected or no response was given""" def __init__(self, msg, response): super().__init__(msg) @@ -58,6 +58,7 @@ def add_retry_code(self, code): """Add a new retry code to""" self.retry_codes.add(code) + # pylint: disable=too-many-locals @backoff.on_exception(backoff.fibo, UnexpectedResponse, max_tries=8, jitter=None) def request( self, @@ -76,21 +77,29 @@ def request( timeout=None, extensions=None, ) -> Response: - response = super().request( - method, - url, - content=content, - data=data, - files=files, - json=json, - params=params, - headers=headers, - cookies=cookies, - auth=auth, - follow_redirects=follow_redirects, - timeout=timeout, - extensions=extensions, - ) - if response.status_code in self.retry_codes: - raise UnexpectedResponse(f"Didn't expect '{response.status_code}' status code", response) - return response + try: + response = super().request( + method, + url, + content=content, + data=data, + files=files, + json=json, + params=params, + headers=headers, + cookies=cookies, + auth=auth, + follow_redirects=follow_redirects, + timeout=timeout, + extensions=extensions, + ) + if response.status_code in self.retry_codes: + raise UnexpectedResponse(f"Didn't expect '{response.status_code}' status code", response) + return response + except ConnectError as e: + # note: when the code reaches this point, negative caching might have been triggered, + # negative caching TTL of SOA record of the zone must be set accordingly, + # otherwise retry will fail if the value is too high + if len(e.args) > 0 and any("Name or service not known" in arg for arg in e.args): + raise UnexpectedResponse("Didn't expect 'Name or service not known' error", None) from e + raise diff --git a/testsuite/tests/mgc/test_basic.py b/testsuite/tests/mgc/test_basic.py index 731a62a2..24dfea72 100644 --- a/testsuite/tests/mgc/test_basic.py +++ b/testsuite/tests/mgc/test_basic.py @@ -13,8 +13,6 @@ * dnspolicies are created and bound to gateways automatically by mgc operator * dnspolicies leak at this moment """ -from time import sleep - import pytest from testsuite.httpx import HttpxBackoffClient @@ -38,7 +36,5 @@ def test_smoke(route, upstream_gateway): # assert that tls_cert is used by the server backend_client = HttpxBackoffClient(base_url=f"https://{route.hostnames[0]}", verify=tls_cert) - sleep(30) # wait for DNS record to propagate correctly; TBD - response = backend_client.get("get") assert response.status_code == 200