2525
2626from custom_metric import create_custom_metric , get_custom_metric
2727from custom_metric import read_timeseries , write_timeseries_value
28+ from gcp .testing import eventually_consistent
2829from gcp .testing .flaky import flaky
2930import 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