16
16
17
17
import random
18
18
import string
19
+ import time
19
20
20
21
from google .api_core .exceptions import Aborted
21
22
from google .cloud import monitoring_v3
@@ -102,15 +103,23 @@ def test_enable_alert_policies(capsys, pochan):
102
103
def invoke_sample (val ):
103
104
snippets .enable_alert_policies (pochan .project_name , val )
104
105
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 )
105
111
invoke_sample (False )
112
+ time .sleep (2 )
106
113
invoke_sample (False )
107
114
out , _ = capsys .readouterr ()
108
115
assert "already disabled" in out
109
116
117
+ time .sleep (2 )
110
118
invoke_sample (True )
111
119
out , _ = capsys .readouterr ()
112
120
assert "Enabled {0}" .format (pochan .project_name ) in out
113
121
122
+ time .sleep (2 )
114
123
invoke_sample (True )
115
124
out , _ = capsys .readouterr ()
116
125
assert "already enabled" in out
@@ -126,6 +135,11 @@ def invoke_sample():
126
135
snippets .replace_notification_channels (
127
136
pochan .project_name , alert_policy_id , [notification_channel_id ])
128
137
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 )
129
143
invoke_sample ()
130
144
out , _ = capsys .readouterr ()
131
145
assert "Updated {0}" .format (pochan .alert_policy .name ) in out
@@ -137,6 +151,11 @@ def test_backup_and_restore(capsys, pochan):
137
151
def invoke_backup ():
138
152
snippets .backup (pochan .project_name , 'backup.json' )
139
153
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 )
140
159
invoke_backup ()
141
160
out , _ = capsys .readouterr ()
142
161
@@ -145,6 +164,7 @@ def invoke_backup():
145
164
def invoke_restore ():
146
165
snippets .restore (pochan .project_name , 'backup.json' )
147
166
167
+ time .sleep (2 )
148
168
invoke_restore ()
149
169
out , _ = capsys .readouterr ()
150
170
assert "Updated {0}" .format (pochan .alert_policy .name ) in out
@@ -161,6 +181,11 @@ def invoke_delete():
161
181
snippets .delete_notification_channels (
162
182
pochan .project_name , [notification_channel_id ], force = True )
163
183
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 )
164
189
invoke_delete ()
165
190
out , _ = capsys .readouterr ()
166
191
assert "{0} deleted" .format (notification_channel_id ) in out
0 commit comments