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

Commit 09d7647

Browse files
author
Takashi Matsuo
authored
[monitoring] fix: use the same random value for retry [(#3900)](GoogleCloudPlatform/python-docs-samples#3900)
* [monitoring] fix: use the same random value for retry fixes #3875 * Just reseed in `write_value()` * revert comment
1 parent 246309a commit 09d7647

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

samples/snippets/v3/api-client/custom_metric_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,15 @@ def test_custom_metric(client, custom_metric):
8383
# Use a constant seed so psuedo random number is known ahead of time
8484
random.seed(1)
8585
pseudo_random_value = random.randint(0, 10)
86-
# Reseed it
87-
random.seed(1)
8886

8987
INSTANCE_ID = "test_instance"
9088

9189
# It's rare, but write can fail with HttpError 500, so we retry.
9290
@backoff.on_exception(backoff.expo, HttpError, max_time=120)
9391
def write_value():
92+
# Reseed it to make sure the sample code will pick the same
93+
# value.
94+
random.seed(1)
9495
write_timeseries_value(client, PROJECT_RESOURCE,
9596
METRIC_RESOURCE, INSTANCE_ID,
9697
METRIC_KIND)
@@ -108,6 +109,6 @@ def eventually_consistent_test():
108109
value = int(
109110
response['timeSeries'][0]['points'][0]['value']['int64Value'])
110111
# using seed of 1 will create a value of 1
111-
assert value == pseudo_random_value
112+
assert pseudo_random_value == value
112113

113114
eventually_consistent_test()

0 commit comments

Comments
 (0)