Skip to content

Commit f3d35f4

Browse files
committed
add wait for trial component to be created to improve test reliability
1 parent 2afeefe commit f3d35f4

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

tests/helpers.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import uuid
1717
import boto3
1818
import sys
19+
import logging
1920

2021

2122
def name():
@@ -145,3 +146,20 @@ def wait_for_job(job_name, get_job, status_field):
145146
sys.stdout.write(".")
146147
sys.stdout.flush()
147148
time.sleep(30)
149+
150+
151+
def wait_for_trial_component(sagemaker_client, training_job_name=None, trial_component_name=None):
152+
# wait for trial component to be created
153+
if training_job_name and not trial_component_name:
154+
# assume tj
155+
trial_component_name = training_job_name + "-aws-training-job"
156+
157+
# wait for the trial component to be created from the training job, usually < 5s
158+
with timeout(minutes=15):
159+
while True:
160+
try:
161+
sagemaker_client.describe_trial_component(TrialComponentName=trial_component_name)
162+
break
163+
except sagemaker_client.exceptions.ResourceNotFound:
164+
logging.info("Trial component %s not created yet.", trial_component_name)
165+
time.sleep(5)

tests/integ/test_tracker.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515

1616
import pytest
1717

18-
from tests.helpers import name
18+
from tests.helpers import name, wait_for_trial_component
1919
from smexperiments import tracker, trial_component, _utils
2020

2121

2222
def test_load_trial_component(trial_component_obj, sagemaker_boto_client):
23+
wait_for_trial_component(sagemaker_boto_client, trial_component_name=trial_component_obj.trial_component_name)
2324
tracker_obj = tracker.Tracker.load(
2425
trial_component_name=trial_component_obj.trial_component_name, sagemaker_boto_client=sagemaker_boto_client
2526
)
@@ -29,6 +30,7 @@ def test_load_trial_component(trial_component_obj, sagemaker_boto_client):
2930

3031
@pytest.mark.docker
3132
def test_load_training_job(training_job_name, sagemaker_boto_client):
33+
wait_for_trial_component(sagemaker_boto_client, training_job_name=training_job_name)
3234
tracker_obj = tracker.Tracker.load(training_job_name=training_job_name, sagemaker_boto_client=sagemaker_boto_client)
3335
assert tracker_obj
3436
assert tracker_obj.trial_component.trial_component_name == training_job_name + "-aws-training-job"

0 commit comments

Comments
 (0)