15
15
'use strict' ;
16
16
17
17
const { assert} = require ( 'chai' ) ;
18
- const { before , describe, it} = require ( 'mocha' ) ;
18
+ const { describe, it} = require ( 'mocha' ) ;
19
19
const { AutoMlClient} = require ( '@google-cloud/automl' ) . v1 ;
20
20
21
21
const cp = require ( 'child_process' ) ;
@@ -26,10 +26,26 @@ const MODEL_ID = 'IOD1656537412546854912';
26
26
const PREDICT_REGION_TAG = 'vision_object_detection_predict' ;
27
27
const LOCATION = 'us-central1' ;
28
28
29
+ // If two suites of tests are running parallel, importing and creating
30
+ // datasets can fail, with:
31
+ // "Another DEPLOY model operation is running on the model".
32
+ const delay = async test => {
33
+ const retries = test . currentRetry ( ) ;
34
+ if ( retries === 0 ) return ; // no retry on the first failure.
35
+ // see: https://cloud.google.com/storage/docs/exponential-backoff:
36
+ const ms = Math . pow ( 2 , retries ) * 1000 + Math . random ( ) * 2000 ;
37
+ return new Promise ( done => {
38
+ console . info ( `retrying "${ test . title } " in ${ ms } ms` ) ;
39
+ setTimeout ( done , ms ) ;
40
+ } ) ;
41
+ } ;
42
+
29
43
describe ( 'Automl Vision Object Detection Predict Test' , ( ) => {
30
44
const client = new AutoMlClient ( ) ;
31
45
32
- before ( 'should verify the model is deployed' , async ( ) => {
46
+ it ( 'should verify the model is deployed' , async function ( ) {
47
+ this . retries ( 5 ) ;
48
+ await delay ( this . test ) ;
33
49
const projectId = await client . getProjectId ( ) ;
34
50
const request = {
35
51
name : client . modelPath ( projectId , LOCATION , MODEL_ID ) ,
0 commit comments