Skip to content

Commit

Permalink
Get batch result
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernard Szabo committed Dec 11, 2024
1 parent 6b17317 commit 44fa556
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions tubular/scripts/dd_synthetic_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DatadogClient:

DATADOG_SYNTHETIC_TESTS_API_URL = "https://api.datadoghq.com/api/v1/synthetics/tests"
DATADOG_SYNTHETIC_TESTS_API_URL = "https://api.datadoghq.com/api/v1/synthetics/tests"
MAX_ALLOWABLE_TIME_SECS = 300 # 5 minutes
MAX_ALLOWABLE_TIME_SECS = 600 # 10 minutes

def __init__(self, api_key, app_key):
self.api_key = api_key
Expand Down Expand Up @@ -63,6 +63,10 @@ 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")

for test in test_requests:
test_result = self._poll_for_test_result(test['id'])
if test_result == False:
Expand Down Expand Up @@ -90,6 +94,22 @@ 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):
url = f"{self.DATADOG_SYNTHETIC_TESTS_API_URL}/ci/batch/{self.test_run_id}"
headers = {
"DD-API-KEY": self.api_key,
"DD-APPLICATION-KEY": self.app_key
}

response = requests.get(url, headers=headers)

if response.status_code != 200:
return None

response_json = response.json()
logging.info(f"Response for batch = {response_json}")


def _get_test_result(self, test_id):
"""
returns JSON structure with test results for all tests in the test run
Expand Down Expand Up @@ -148,15 +168,6 @@ def run_synthetic_tests(enable_automated_rollbacks, slack_notification_channel):
# PUBLIC_TEST_ID = "sad-hqu-h33"
# tests_to_run = json.loads(os.getenv("TESTS_TO_RUN"))
tests_to_run = [

{
"name":
'''
edX Smoke Test - [Unenrolled student] An unenrolled student cannot load a
course’s landing page, and sees the “Enroll Now” screen
''',
"id": "zkx-36f-kui"
},
{
"name":
'''
Expand All @@ -165,6 +176,14 @@ def run_synthetic_tests(enable_automated_rollbacks, slack_notification_channel):
''',
"id": "6tq-u28-hwa"
},
{
"name":
'''
edX Smoke Test - [Unenrolled student] An unenrolled student cannot load a
course’s landing page, and sees the “Enroll Now” screen
''',
"id": "zkx-36f-kui"
},
{
"name":
'''
Expand Down

0 comments on commit 44fa556

Please sign in to comment.