Skip to content

Commit

Permalink
[monitoring] fix: use the same random value for retry (#3900)
Browse files Browse the repository at this point in the history
* [monitoring] fix: use the same random value for retry

fixes #3875

* Just reseed in `write_value()`

* revert comment
  • Loading branch information
Takashi Matsuo authored May 28, 2020
1 parent 87eb8a0 commit 3cc468d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions monitoring/api/v3/api-client/custom_metric_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()

0 comments on commit 3cc468d

Please sign in to comment.