Skip to content

Commit

Permalink
Poll for batch result
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernard Szabo committed Dec 11, 2024
1 parent 44fa556 commit ca89be5
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions tubular/scripts/dd_synthetic_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down Expand Up @@ -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,
Expand All @@ -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):
Expand Down

0 comments on commit ca89be5

Please sign in to comment.