From ca89be54ea711b20aee6d0fb76cdbad98ddde4c7 Mon Sep 17 00:00:00 2001 From: Bernard Szabo Date: Wed, 11 Dec 2024 16:29:45 -0500 Subject: [PATCH] Poll for batch result --- tubular/scripts/dd_synthetic_tests.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tubular/scripts/dd_synthetic_tests.py b/tubular/scripts/dd_synthetic_tests.py index 2bb4266a..32d75535 100644 --- a/tubular/scripts/dd_synthetic_tests.py +++ b/tubular/scripts/dd_synthetic_tests.py @@ -63,9 +63,12 @@ def get_failed_tests(self, test_requests): :return: A list of the test ids for the tests that failed; Empty list if all tests passed ''' failed_tests = [] - time.sleep(120) - self._get_batch_result(self.test_run_id) - logging.info("Done getting batch result") + batch_result = None + while batch_result is None and (time.time() - self.trigger_time) < (self.MAX_ALLOWABLE_TIME_SECS): + time.sleep(5) # Poll every 5 seconds + batch_result = self._get_batch_result() + logging.info(f"Done getting batch result at time {time.time()}") + logging.info(f"Batch result: {batch_result}") for test in test_requests: test_result = self._poll_for_test_result(test['id']) @@ -94,7 +97,7 @@ def _poll_for_test_result(self, test_id): logging.info(f'Test {test_id} finished at time {completion_time} with {test_result=}') return test_result - def _get_batch_result(self, test_run_id): + def _get_batch_result(self): url = f"{self.DATADOG_SYNTHETIC_TESTS_API_URL}/ci/batch/{self.test_run_id}" headers = { "DD-API-KEY": self.api_key, @@ -104,10 +107,11 @@ def _get_batch_result(self, test_run_id): response = requests.get(url, headers=headers) if response.status_code != 200: + logging.info(f"Get batch results returned status of {response.status_code}") return None response_json = response.json() - logging.info(f"Response for batch = {response_json}") + return response_json def _get_test_result(self, test_id):