@@ -32,6 +32,19 @@ const cmd = 'node alerts';
32
32
let policyOneName , policyTwoName , channelName ;
33
33
const testPrefix = `gcloud-test-${ uuid . v4 ( ) . split ( '-' ) [ 0 ] } ` ;
34
34
35
+ // Tests in this suite can trigger the error,
36
+ // "Too many concurrent edits to the project configuration. Please try again".
37
+ const delay = async test => {
38
+ const retries = test . currentRetry ( ) ;
39
+ if ( retries === 0 ) return ; // no retry on the first failure.
40
+ // see: https://cloud.google.com/storage/docs/exponential-backoff:
41
+ const ms = Math . pow ( 2 , retries ) * 500 + Math . random ( ) * 2000 ;
42
+ return new Promise ( done => {
43
+ console . info ( `retrying "${ test . title } " in ${ ms } ms` ) ;
44
+ setTimeout ( done , ms ) ;
45
+ } ) ;
46
+ } ;
47
+
35
48
describe ( 'alerts' , ( ) => {
36
49
before ( async ( ) => {
37
50
await reapPolicies ( ) ;
@@ -162,13 +175,17 @@ describe('alerts', () => {
162
175
await deleteChannels ( ) ;
163
176
} ) ;
164
177
165
- it ( 'should replace notification channels' , ( ) => {
178
+ it ( 'should replace notification channels' , async function ( ) {
179
+ this . retries ( 8 ) ;
180
+ await delay ( this . test ) ;
166
181
const stdout = execSync ( `${ cmd } replace ${ policyOneName } ${ channelName } ` ) ;
167
182
assert . include ( stdout , 'Updated projects' ) ;
168
183
assert . include ( stdout , policyOneName ) ;
169
184
} ) ;
170
185
171
- it ( 'should disable policies' , ( ) => {
186
+ it ( 'should disable policies' , async function ( ) {
187
+ this . retries ( 8 ) ;
188
+ await delay ( this . test ) ;
172
189
const stdout = execSync (
173
190
`${ cmd } disable ${ projectId } 'display_name.size < 28'`
174
191
) ;
@@ -177,7 +194,9 @@ describe('alerts', () => {
177
194
assert . include ( stdout , policyTwoName ) ;
178
195
} ) ;
179
196
180
- it ( 'should enable policies' , ( ) => {
197
+ it ( 'should enable policies' , async function ( ) {
198
+ this . retries ( 8 ) ;
199
+ await delay ( this . test ) ;
181
200
const stdout = execSync (
182
201
`${ cmd } enable ${ projectId } 'display_name.size < 28'`
183
202
) ;
@@ -194,14 +213,18 @@ describe('alerts', () => {
194
213
assert . include ( stdout , 'second' ) ;
195
214
} ) ;
196
215
197
- it ( 'should backup all policies' , async ( ) => {
216
+ it ( 'should backup all policies' , async function ( ) {
217
+ this . retries ( 8 ) ;
218
+ await delay ( this . test ) ;
198
219
const output = execSync ( `${ cmd } backup ${ projectId } ` ) ;
199
220
assert . include ( output , 'Saved policies to ./policies_backup.json' ) ;
200
221
assert . ok ( fs . existsSync ( path . join ( __dirname , '../policies_backup.json' ) ) ) ;
201
222
await client . deleteAlertPolicy ( { name : policyOneName } ) ;
202
223
} ) ;
203
224
204
- it ( 'should restore policies' , ( ) => {
225
+ it ( 'should restore policies' , async function ( ) {
226
+ this . retries ( 8 ) ;
227
+ await delay ( this . test ) ;
205
228
const output = execSync ( `${ cmd } restore ${ projectId } ` ) ;
206
229
assert . include ( output , 'Loading policies from ./policies_backup.json' ) ;
207
230
const matches = output . match (
0 commit comments