25
25
26
26
from custom_metric import create_custom_metric , get_custom_metric
27
27
from custom_metric import read_timeseries , write_timeseries_value
28
+ from gcp .testing import eventually_consistent
28
29
from gcp .testing .flaky import flaky
29
30
import list_resources
30
31
@@ -53,9 +54,10 @@ def test_custom_metric(cloud_config):
53
54
54
55
create_custom_metric (
55
56
client , PROJECT_RESOURCE , METRIC_RESOURCE , METRIC_KIND )
56
- custom_metric = None
57
+
57
58
# wait until metric has been created, use the get call to wait until
58
59
# a response comes back with the new metric
60
+ custom_metric = None
59
61
while not custom_metric :
60
62
time .sleep (1 )
61
63
custom_metric = get_custom_metric (
@@ -64,12 +66,13 @@ def test_custom_metric(cloud_config):
64
66
write_timeseries_value (client , PROJECT_RESOURCE ,
65
67
METRIC_RESOURCE , INSTANCE_ID ,
66
68
METRIC_KIND )
69
+
67
70
# 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