Skip to content

Commit 616367a

Browse files
author
Takashi Matsuo
committed
[monitoring] testing: mitigate 409 conflicts
fixes GoogleCloudPlatform#2971
1 parent 35ded53 commit 616367a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

monitoring/api/v3/alerts-client/snippets_test.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import random
1818
import string
19+
import time
1920

2021
from google.api_core.exceptions import Aborted
2122
from google.cloud import monitoring_v3
@@ -102,15 +103,23 @@ def test_enable_alert_policies(capsys, pochan):
102103
def invoke_sample(val):
103104
snippets.enable_alert_policies(pochan.project_name, val)
104105

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)