Skip to content

Commit

Permalink
add randomness to the sleep calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Takashi Matsuo committed Apr 8, 2020
1 parent 7d3816a commit d40777a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion monitoring/api/v3/alerts-client/snippets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
Expand All @@ -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

Expand Down

0 comments on commit d40777a

Please sign in to comment.