Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

Commit

Permalink
Fix flaky custom metric test.
Browse files Browse the repository at this point in the history
Change-Id: Ia2628f205537099d28415412fe302763f17c3081
  • Loading branch information
Jon Wayne Parrott committed Aug 2, 2016
1 parent 31eea9a commit 4b3c58e
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions samples/snippets/v3/custom_metric_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

from custom_metric import create_custom_metric, get_custom_metric
from custom_metric import read_timeseries, write_timeseries_value
from gcp.testing import eventually_consistent
from gcp.testing.flaky import flaky
import list_resources

Expand Down Expand Up @@ -53,9 +54,10 @@ def test_custom_metric(cloud_config):

create_custom_metric(
client, PROJECT_RESOURCE, METRIC_RESOURCE, METRIC_KIND)
custom_metric = None

# wait until metric has been created, use the get call to wait until
# a response comes back with the new metric
custom_metric = None
while not custom_metric:
time.sleep(1)
custom_metric = get_custom_metric(
Expand All @@ -64,12 +66,13 @@ def test_custom_metric(cloud_config):
write_timeseries_value(client, PROJECT_RESOURCE,
METRIC_RESOURCE, INSTANCE_ID,
METRIC_KIND)

# Sometimes on new metric descriptors, writes have a delay in being
# read back. 3 seconds should be enough to make sure our read call
# picks up the write
time.sleep(3)
response = read_timeseries(client, PROJECT_RESOURCE, METRIC_RESOURCE)
value = int(
response['timeSeries'][0]['points'][0]['value']['int64Value'])
# using seed of 1 will create a value of 1
assert value == pseudo_random_value
# read back. Use eventually_consistent to account for this.
@eventually_consistent.call
def _():
response = read_timeseries(client, PROJECT_RESOURCE, METRIC_RESOURCE)
value = int(
response['timeSeries'][0]['points'][0]['value']['int64Value'])
# using seed of 1 will create a value of 1
assert value == pseudo_random_value

0 comments on commit 4b3c58e

Please sign in to comment.