diff --git a/kubernetes_tests/test_base.py b/kubernetes_tests/test_base.py index ac311daa52f8c1..6929128173cbf6 100644 --- a/kubernetes_tests/test_base.py +++ b/kubernetes_tests/test_base.py @@ -29,6 +29,7 @@ import requests import requests.exceptions from requests.adapters import HTTPAdapter +from urllib3.exceptions import MaxRetryError from urllib3.util.retry import Retry CLUSTER_FORWARDED_PORT = os.environ.get("CLUSTER_FORWARDED_PORT") or "8080" @@ -125,7 +126,7 @@ def _get_session_with_retries(self): session.auth = ("admin", "admin") retries = Retry( total=3, - backoff_factor=1, + backoff_factor=10, status_forcelist=[404], allowed_methods=Retry.DEFAULT_ALLOWED_METHODS | frozenset(["PATCH", "POST"]), ) @@ -225,10 +226,16 @@ def start_dag(self, dag_id, host): print(f"Calling [start_dag]#1 {patch_string}") max_attempts = 10 result = {} + # This loop retries until the DAG parser finishes with max_attempts and the DAG is available for execution. + # Keep the try/catch block, as the session object has a default retry configuration. + # If a MaxRetryError is raised, it can be safely ignored, indicating that the DAG is not yet parsed. while max_attempts: - result = self.session.patch(patch_string, json={"is_paused": False}) - if result.status_code == 200: - break + try: + result = self.session.patch(patch_string, json={"is_paused": False}) + if result.status_code == 200: + break + except MaxRetryError: + pass time.sleep(30) max_attempts -= 1