Skip to content

Commit fa29b69

Browse files
danabensqidewenwhen
authored andcommitted
fix flaky metrics test (aws#753)
1 parent cfae9a3 commit fa29b69

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

tests/integ/sagemaker/experiments/test_metrics.py

+10-21
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,24 @@
1414
import random
1515
from sagemaker.experiments._metrics import _MetricsManager
1616
from sagemaker.experiments.trial_component import _TrialComponent
17+
import time
1718

1819

19-
def test_epoch(trial_component_obj, sagemaker_session):
20+
def test_end_to_end(trial_component_obj, sagemaker_session):
2021
# The fixture creates deletes, just ensure fixture is used at least once
21-
metric_name = "test-x-step"
2222
with _MetricsManager(trial_component_obj.trial_component_arn, sagemaker_session) as mm:
2323
for i in range(100):
24-
mm.log_metric(metric_name, random.random(), step=i)
24+
mm.log_metric("test-x-step", random.random(), step=i)
25+
mm.log_metric("test-x-timestamp", random.random())
2526

26-
updated_tc = _TrialComponent.load(
27-
trial_component_name=trial_component_obj.trial_component_name,
28-
sagemaker_session=sagemaker_session,
29-
)
30-
assert len(updated_tc.metrics) == 1
31-
assert updated_tc.metrics[0].metric_name == metric_name
32-
33-
34-
def test_timestamp(trial_component_obj, sagemaker_session):
35-
# The fixture creates deletes, just ensure fixture is used at least once
36-
metric_name = "test-x-timestamp"
37-
with _MetricsManager(trial_component_obj.trial_component_arn, sagemaker_session) as mm:
38-
for i in range(100):
39-
mm.log_metric(metric_name, random.random())
27+
# metrics -> eureka propagation
28+
time.sleep(3)
4029

4130
updated_tc = _TrialComponent.load(
4231
trial_component_name=trial_component_obj.trial_component_name,
4332
sagemaker_session=sagemaker_session,
4433
)
45-
# the test-x-step data is added in the previous test_epoch test
46-
assert len(updated_tc.metrics) == 2
47-
assert updated_tc.metrics[0].metric_name == "test-x-step"
48-
assert updated_tc.metrics[1].metric_name == "test-x-timestamp"
34+
metrics = updated_tc.metrics
35+
assert len(metrics) == 2
36+
assert list(filter(lambda x: x.metric_name == "test-x-step", metrics))
37+
assert list(filter(lambda x: x.metric_name == "test-x-timestamp", metrics))

0 commit comments

Comments
 (0)