Skip to content

Commit 0bd312a

Browse files
committed
retry downstream_trials test
1 parent 919992a commit 0bd312a

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

tests/integ/sagemaker/lineage/helpers.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
import uuid
1717
from datetime import datetime
18-
18+
from contextlib import contextmanager
19+
import time
1920

2021
def name():
2122
return "lineage-integ-{}-{}".format(
@@ -30,3 +31,15 @@ def names():
3031
)
3132
for i in range(3)
3233
]
34+
35+
def retry(callable, num_attempts=8):
36+
assert num_attempts >= 1
37+
for i in range(num_attempts):
38+
try:
39+
return callable()
40+
except Exception as ex:
41+
if i == num_attempts - 1:
42+
raise ex
43+
print("Retrying", ex)
44+
time.sleep(2 ** i)
45+
assert False, "logic error in retry"

tests/integ/sagemaker/lineage/test_artifact.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import pytest
2121

2222
from sagemaker.lineage import artifact
23-
23+
from tests.integ.sagemaker.lineage.helpers import retry
2424

2525
def test_create_delete(artifact_obj):
2626
# fixture does create and then delete, this test ensures it happens at least once
@@ -103,14 +103,18 @@ def test_list_by_type(artifact_objs, sagemaker_session):
103103

104104
def test_downstream_trials(trial_associated_artifact, trial_obj, sagemaker_session):
105105
# allow trial components to index, 30 seconds max
106-
for i in range(3):
107-
time.sleep(10)
108-
trials = trial_associated_artifact.downstream_trials(sagemaker_session=sagemaker_session)
109-
if len(trials) > 0:
110-
break
111-
112-
assert len(trials) == 1
113-
assert trial_obj.trial_name in trials
106+
def validate():
107+
for i in range(3):
108+
time.sleep(10)
109+
trials = trial_associated_artifact.downstream_trials(sagemaker_session=sagemaker_session)
110+
logging.info(f'Found {len(trials)} downstream trials.')
111+
if len(trials) > 0:
112+
break
113+
114+
assert len(trials) == 1
115+
assert trial_obj.trial_name in trials
116+
117+
retry(validate, num_attempts=3)
114118

115119

116120
@pytest.mark.timeout(30)

0 commit comments

Comments
 (0)