Skip to content

Commit 3d14d59

Browse files
author
Jon Wayne Parrott
committed
Fix flaky custom metric test.
Change-Id: Ia2628f205537099d28415412fe302763f17c3081
1 parent dd2ffca commit 3d14d59

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

monitoring/api/v3/custom_metric_test.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
from custom_metric import create_custom_metric, get_custom_metric
2727
from custom_metric import read_timeseries, write_timeseries_value
28+
from gcp.testing import eventually_consistent
2829
from gcp.testing.flaky import flaky
2930
import list_resources
3031

@@ -53,9 +54,10 @@ def test_custom_metric(cloud_config):
5354

5455
create_custom_metric(
5556
client, PROJECT_RESOURCE, METRIC_RESOURCE, METRIC_KIND)
56-
custom_metric = None
57+
5758
# wait until metric has been created, use the get call to wait until
5859
# a response comes back with the new metric
60+
custom_metric = None
5961
while not custom_metric:
6062
time.sleep(1)
6163
custom_metric = get_custom_metric(
@@ -64,12 +66,13 @@ def test_custom_metric(cloud_config):
6466
write_timeseries_value(client, PROJECT_RESOURCE,
6567
METRIC_RESOURCE, INSTANCE_ID,
6668
METRIC_KIND)
69+
6770
# Sometimes on new metric descriptors, writes have a delay in being
68-
# read back. 3 seconds should be enough to make sure our read call
69-
# picks up the write
70-
time.sleep(3)
71-
response = read_timeseries(client, PROJECT_RESOURCE, METRIC_RESOURCE)
72-
value = int(
73-
response['timeSeries'][0]['points'][0]['value']['int64Value'])
74-
# using seed of 1 will create a value of 1
75-
assert value == pseudo_random_value
71+
# read back. Use eventually_consistent to account for this.
72+
@eventually_consistent.call
73+
def _():
74+
response = read_timeseries(client, PROJECT_RESOURCE, METRIC_RESOURCE)
75+
value = int(
76+
response['timeSeries'][0]['points'][0]['value']['int64Value'])
77+
# using seed of 1 will create a value of 1
78+
assert value == pseudo_random_value

0 commit comments

Comments
 (0)