Skip to content

Commit ead0351

Browse files
danabensnavinsoni
andauthored
change: retry downstream_trials test (#2712)
Co-authored-by: Navin Soni <[email protected]>
1 parent 67fa816 commit ead0351

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

tests/integ/sagemaker/lineage/helpers.py

+14
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import uuid
1717
from datetime import datetime
18+
import time
1819

1920

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

tests/integ/sagemaker/lineage/test_artifact.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import pytest
2121

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

2425

2526
def test_create_delete(artifact_obj):
@@ -103,14 +104,20 @@ def test_list_by_type(artifact_objs, sagemaker_session):
103104

104105
def test_downstream_trials(trial_associated_artifact, trial_obj, sagemaker_session):
105106
# 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
107+
def validate():
108+
for i in range(3):
109+
time.sleep(10)
110+
trials = trial_associated_artifact.downstream_trials(
111+
sagemaker_session=sagemaker_session
112+
)
113+
logging.info(f"Found {len(trials)} downstream trials.")
114+
if len(trials) > 0:
115+
break
116+
117+
assert len(trials) == 1
118+
assert trial_obj.trial_name in trials
111119

112-
assert len(trials) == 1
113-
assert trial_obj.trial_name in trials
120+
retry(validate, num_attempts=3)
114121

115122

116123
@pytest.mark.timeout(30)

0 commit comments

Comments
 (0)