From d40777a213f3dce7ec5c533c7cb80189b7de250f Mon Sep 17 00:00:00 2001 From: Takashi Matsuo Date: Wed, 8 Apr 2020 14:59:11 -0700 Subject: [PATCH] add randomness to the sleep calls --- monitoring/api/v3/alerts-client/snippets_test.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/monitoring/api/v3/alerts-client/snippets_test.py b/monitoring/api/v3/alerts-client/snippets_test.py index 74e887572c20..766c54654a32 100644 --- a/monitoring/api/v3/alerts-client/snippets_test.py +++ b/monitoring/api/v3/alerts-client/snippets_test.py @@ -28,6 +28,10 @@ import snippets +# We assume we have access to good randomness source. +random.seed() + + def random_name(length): return ''.join( [random.choice(string.ascii_lowercase) for i in range(length)]) @@ -39,7 +43,8 @@ def retry_if_aborted(exception): def delay_on_aborted(err, *args): if retry_if_aborted(err[1]): - time.sleep(2) + # add randomness for avoiding continuous conflict + time.sleep(2 + (random.randint(0, 9) * 0.1)) return True return False