From 3cc468d18804cf5cc388a933a2b21ceaa20d1466 Mon Sep 17 00:00:00 2001 From: Takashi Matsuo Date: Thu, 28 May 2020 13:20:28 -0700 Subject: [PATCH] [monitoring] fix: use the same random value for retry (#3900) * [monitoring] fix: use the same random value for retry fixes #3875 * Just reseed in `write_value()` * revert comment --- monitoring/api/v3/api-client/custom_metric_test.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/monitoring/api/v3/api-client/custom_metric_test.py b/monitoring/api/v3/api-client/custom_metric_test.py index 1a80408c4adf..e2daa0964139 100644 --- a/monitoring/api/v3/api-client/custom_metric_test.py +++ b/monitoring/api/v3/api-client/custom_metric_test.py @@ -83,14 +83,15 @@ def test_custom_metric(client, custom_metric): # Use a constant seed so psuedo random number is known ahead of time random.seed(1) pseudo_random_value = random.randint(0, 10) - # Reseed it - random.seed(1) INSTANCE_ID = "test_instance" # It's rare, but write can fail with HttpError 500, so we retry. @backoff.on_exception(backoff.expo, HttpError, max_time=120) def write_value(): + # Reseed it to make sure the sample code will pick the same + # value. + random.seed(1) write_timeseries_value(client, PROJECT_RESOURCE, METRIC_RESOURCE, INSTANCE_ID, METRIC_KIND) @@ -108,6 +109,6 @@ def eventually_consistent_test(): value = int( response['timeSeries'][0]['points'][0]['value']['int64Value']) # using seed of 1 will create a value of 1 - assert value == pseudo_random_value + assert pseudo_random_value == value eventually_consistent_test()