@@ -58,6 +58,19 @@ const cwd = path.join(__dirname, '..');
58
58
const videoFile = `testdata/${ testFileName } ` ;
59
59
const overlayFile = `testdata/${ testOverlayFileName } ` ;
60
60
61
+ const delay = async ( test , addMs ) => {
62
+ const retries = test . currentRetry ( ) ;
63
+ await new Promise ( r => setTimeout ( r , addMs ) ) ;
64
+ // No retry on the first failure.
65
+ if ( retries === 0 ) return ;
66
+ // See: https://cloud.google.com/storage/docs/exponential-backoff
67
+ const ms = Math . pow ( 2 , retries ) * 10000 + Math . random ( ) * 1000 ;
68
+ return new Promise ( done => {
69
+ console . info ( `retrying "${ test . title } " in ${ ms } ms` ) ;
70
+ setTimeout ( done , ms ) ;
71
+ } ) ;
72
+ } ;
73
+
61
74
function wait ( ms ) {
62
75
return new Promise ( resolve => {
63
76
setTimeout ( ( ) => {
@@ -193,12 +206,23 @@ describe('Job functions preset', () => {
193
206
it ( 'should check that the job succeeded' , async function ( ) {
194
207
this . retries ( 5 ) ;
195
208
createJobFromPreset ( ) ;
196
- await wait ( 90000 ) ;
197
- const output = execSync (
198
- `node getJobState.js ${ projectId } ${ location } ${ presetJobId } ` ,
199
- { cwd}
200
- ) ;
201
- assert . ok ( output . includes ( 'Job state: SUCCEEDED' ) ) ;
209
+ await delay ( this . test , 30000 ) ;
210
+
211
+ let getAttempts = 0 ;
212
+ while ( getAttempts < 5 ) {
213
+ const ms = Math . pow ( 2 , getAttempts + 1 ) * 10000 + Math . random ( ) * 1000 ;
214
+ await wait ( ms ) ;
215
+ const output = execSync (
216
+ `node getJobState.js ${ projectId } ${ location } ${ presetJobId } ` ,
217
+ { cwd}
218
+ ) ;
219
+ if ( output . includes ( 'Job state: SUCCEEDED' ) ) {
220
+ assert . ok ( true ) ;
221
+ return ;
222
+ }
223
+ getAttempts ++ ;
224
+ }
225
+ assert . ok ( false ) ;
202
226
} ) ;
203
227
} ) ;
204
228
@@ -251,12 +275,23 @@ describe('Job functions template', () => {
251
275
252
276
it ( 'should check that the job succeeded' , async function ( ) {
253
277
this . retries ( 5 ) ;
254
- await wait ( 90000 ) ;
255
- const output = execSync (
256
- `node getJobState.js ${ projectId } ${ location } ${ this . templateJobId } ` ,
257
- { cwd}
258
- ) ;
259
- assert . ok ( output . includes ( 'Job state: SUCCEEDED' ) ) ;
278
+ await delay ( this . test , 30000 ) ;
279
+
280
+ let getAttempts = 0 ;
281
+ while ( getAttempts < 5 ) {
282
+ const ms = Math . pow ( 2 , getAttempts + 1 ) * 10000 + Math . random ( ) * 1000 ;
283
+ await wait ( ms ) ;
284
+ const output = execSync (
285
+ `node getJobState.js ${ projectId } ${ location } ${ this . templateJobId } ` ,
286
+ { cwd}
287
+ ) ;
288
+ if ( output . includes ( 'Job state: SUCCEEDED' ) ) {
289
+ assert . ok ( true ) ;
290
+ return ;
291
+ }
292
+ getAttempts ++ ;
293
+ }
294
+ assert . ok ( false ) ;
260
295
} ) ;
261
296
} ) ;
262
297
@@ -299,12 +334,23 @@ describe('Job functions adhoc', () => {
299
334
300
335
it ( 'should check that the job succeeded' , async function ( ) {
301
336
this . retries ( 5 ) ;
302
- await wait ( 90000 ) ;
303
- const output = execSync (
304
- `node getJobState.js ${ projectId } ${ location } ${ this . adhocJobId } ` ,
305
- { cwd}
306
- ) ;
307
- assert . ok ( output . includes ( 'Job state: SUCCEEDED' ) ) ;
337
+ await delay ( this . test , 30000 ) ;
338
+
339
+ let getAttempts = 0 ;
340
+ while ( getAttempts < 5 ) {
341
+ const ms = Math . pow ( 2 , getAttempts + 1 ) * 10000 + Math . random ( ) * 1000 ;
342
+ await wait ( ms ) ;
343
+ const output = execSync (
344
+ `node getJobState.js ${ projectId } ${ location } ${ this . adhocJobId } ` ,
345
+ { cwd}
346
+ ) ;
347
+ if ( output . includes ( 'Job state: SUCCEEDED' ) ) {
348
+ assert . ok ( true ) ;
349
+ return ;
350
+ }
351
+ getAttempts ++ ;
352
+ }
353
+ assert . ok ( false ) ;
308
354
} ) ;
309
355
} ) ;
310
356
@@ -339,12 +385,23 @@ describe('Job with static overlay functions', () => {
339
385
340
386
it ( 'should check that the job succeeded' , async function ( ) {
341
387
this . retries ( 5 ) ;
342
- await wait ( 90000 ) ;
343
- const output = execSync (
344
- `node getJobState.js ${ projectId } ${ location } ${ this . staticOverlayJobId } ` ,
345
- { cwd}
346
- ) ;
347
- assert . ok ( output . includes ( 'Job state: SUCCEEDED' ) ) ;
388
+ await delay ( this . test , 30000 ) ;
389
+
390
+ let getAttempts = 0 ;
391
+ while ( getAttempts < 5 ) {
392
+ const ms = Math . pow ( 2 , getAttempts + 1 ) * 10000 + Math . random ( ) * 1000 ;
393
+ await wait ( ms ) ;
394
+ const output = execSync (
395
+ `node getJobState.js ${ projectId } ${ location } ${ this . staticOverlayJobId } ` ,
396
+ { cwd}
397
+ ) ;
398
+ if ( output . includes ( 'Job state: SUCCEEDED' ) ) {
399
+ assert . ok ( true ) ;
400
+ return ;
401
+ }
402
+ getAttempts ++ ;
403
+ }
404
+ assert . ok ( false ) ;
348
405
} ) ;
349
406
} ) ;
350
407
@@ -379,12 +436,23 @@ describe('Job with animated overlay functions', () => {
379
436
380
437
it ( 'should check that the job succeeded' , async function ( ) {
381
438
this . retries ( 5 ) ;
382
- await wait ( 90000 ) ;
383
- const output = execSync (
384
- `node getJobState.js ${ projectId } ${ location } ${ this . animatedOverlayJobId } ` ,
385
- { cwd}
386
- ) ;
387
- assert . ok ( output . includes ( 'Job state: SUCCEEDED' ) ) ;
439
+ await delay ( this . test , 30000 ) ;
440
+
441
+ let getAttempts = 0 ;
442
+ while ( getAttempts < 5 ) {
443
+ const ms = Math . pow ( 2 , getAttempts + 1 ) * 10000 + Math . random ( ) * 1000 ;
444
+ await wait ( ms ) ;
445
+ const output = execSync (
446
+ `node getJobState.js ${ projectId } ${ location } ${ this . animatedOverlayJobId } ` ,
447
+ { cwd}
448
+ ) ;
449
+ if ( output . includes ( 'Job state: SUCCEEDED' ) ) {
450
+ assert . ok ( true ) ;
451
+ return ;
452
+ }
453
+ getAttempts ++ ;
454
+ }
455
+ assert . ok ( false ) ;
388
456
} ) ;
389
457
} ) ;
390
458
@@ -419,12 +487,23 @@ describe('Job with set number of images spritesheet', () => {
419
487
420
488
it ( 'should check that the job succeeded' , async function ( ) {
421
489
this . retries ( 5 ) ;
422
- await wait ( 90000 ) ;
423
- const output = execSync (
424
- `node getJobState.js ${ projectId } ${ location } ${ this . setNumberSpritesheetJobId } ` ,
425
- { cwd}
426
- ) ;
427
- assert . ok ( output . includes ( 'Job state: SUCCEEDED' ) ) ;
490
+ await delay ( this . test , 30000 ) ;
491
+
492
+ let getAttempts = 0 ;
493
+ while ( getAttempts < 5 ) {
494
+ const ms = Math . pow ( 2 , getAttempts + 1 ) * 10000 + Math . random ( ) * 1000 ;
495
+ await wait ( ms ) ;
496
+ const output = execSync (
497
+ `node getJobState.js ${ projectId } ${ location } ${ this . setNumberSpritesheetJobId } ` ,
498
+ { cwd}
499
+ ) ;
500
+ if ( output . includes ( 'Job state: SUCCEEDED' ) ) {
501
+ assert . ok ( true ) ;
502
+ return ;
503
+ }
504
+ getAttempts ++ ;
505
+ }
506
+ assert . ok ( false ) ;
428
507
} ) ;
429
508
430
509
it ( 'should check that the spritesheet files exist in the bucket' , async ( ) => {
@@ -476,12 +555,23 @@ describe('Job with periodic images spritesheet', () => {
476
555
477
556
it ( 'should check that the job succeeded' , async function ( ) {
478
557
this . retries ( 5 ) ;
479
- await wait ( 90000 ) ;
480
- const output = execSync (
481
- `node getJobState.js ${ projectId } ${ location } ${ this . periodicSpritesheetJobId } ` ,
482
- { cwd}
483
- ) ;
484
- assert . ok ( output . includes ( 'Job state: SUCCEEDED' ) ) ;
558
+ await delay ( this . test , 30000 ) ;
559
+
560
+ let getAttempts = 0 ;
561
+ while ( getAttempts < 5 ) {
562
+ const ms = Math . pow ( 2 , getAttempts + 1 ) * 10000 + Math . random ( ) * 1000 ;
563
+ await wait ( ms ) ;
564
+ const output = execSync (
565
+ `node getJobState.js ${ projectId } ${ location } ${ this . periodicSpritesheetJobId } ` ,
566
+ { cwd}
567
+ ) ;
568
+ if ( output . includes ( 'Job state: SUCCEEDED' ) ) {
569
+ assert . ok ( true ) ;
570
+ return ;
571
+ }
572
+ getAttempts ++ ;
573
+ }
574
+ assert . ok ( false ) ;
485
575
} ) ;
486
576
487
577
it ( 'should check that the spritesheet files exist in the bucket' , async ( ) => {
0 commit comments