Skip to content

Commit

Permalink
[monitoring] testing: mitigate 409 conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Takashi Matsuo committed Apr 8, 2020
1 parent 35ded53 commit 616367a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions monitoring/api/v3/alerts-client/snippets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import random
import string
import time

from google.api_core.exceptions import Aborted
from google.cloud import monitoring_v3
Expand Down Expand Up @@ -102,15 +103,23 @@ def test_enable_alert_policies(capsys, pochan):
def invoke_sample(val):
snippets.enable_alert_policies(pochan.project_name, val)

# These sleep calls are for mitigating the following error:
# "409 Too many concurrent edits to the project configuration.
# Please try again."
# TODO(#3310): Having multiple projects will void these `sleep()` calls
time.sleep(2)
invoke_sample(False)
time.sleep(2)
invoke_sample(False)
out, _ = capsys.readouterr()
assert "already disabled" in out

time.sleep(2)
invoke_sample(True)
out, _ = capsys.readouterr()
assert "Enabled {0}".format(pochan.project_name) in out

time.sleep(2)
invoke_sample(True)
out, _ = capsys.readouterr()
assert "already enabled" in out
Expand All @@ -126,6 +135,11 @@ def invoke_sample():
snippets.replace_notification_channels(
pochan.project_name, alert_policy_id, [notification_channel_id])

# This sleep call is for mitigating the following error:
# "409 Too many concurrent edits to the project configuration.
# Please try again."
# TODO(#3310): Having multiple projects will void this `sleep()` call.
time.sleep(2)
invoke_sample()
out, _ = capsys.readouterr()
assert "Updated {0}".format(pochan.alert_policy.name) in out
Expand All @@ -137,6 +151,11 @@ def test_backup_and_restore(capsys, pochan):
def invoke_backup():
snippets.backup(pochan.project_name, 'backup.json')

# These sleep calls are for mitigating the following error:
# "409 Too many concurrent edits to the project configuration.
# Please try again."
# TODO(#3310): Having multiple projects will void these `sleep()` calls
time.sleep(2)
invoke_backup()
out, _ = capsys.readouterr()

Expand All @@ -145,6 +164,7 @@ def invoke_backup():
def invoke_restore():
snippets.restore(pochan.project_name, 'backup.json')

time.sleep(2)
invoke_restore()
out, _ = capsys.readouterr()
assert "Updated {0}".format(pochan.alert_policy.name) in out
Expand All @@ -161,6 +181,11 @@ def invoke_delete():
snippets.delete_notification_channels(
pochan.project_name, [notification_channel_id], force=True)

# This sleep call is for mitigating the following error:
# "409 Too many concurrent edits to the project configuration.
# Please try again."
# TODO(#3310): Having multiple projects will void this `sleep()` call.
time.sleep(2)
invoke_delete()
out, _ = capsys.readouterr()
assert "{0} deleted".format(notification_channel_id) in out
Expand Down

0 comments on commit 616367a

Please sign in to comment.