1515'use strict' ;
1616
1717const { assert} = require ( 'chai' ) ;
18- const { before , describe, it} = require ( 'mocha' ) ;
18+ const { describe, it} = require ( 'mocha' ) ;
1919const { AutoMlClient} = require ( '@google-cloud/automl' ) . v1 ;
2020
2121const cp = require ( 'child_process' ) ;
@@ -26,10 +26,26 @@ const MODEL_ID = 'IOD1656537412546854912';
2626const PREDICT_REGION_TAG = 'vision_object_detection_predict' ;
2727const LOCATION = 'us-central1' ;
2828
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+
2943describe ( 'Automl Vision Object Detection Predict Test' , ( ) => {
3044 const client = new AutoMlClient ( ) ;
3145
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 ) ;
3349 const projectId = await client . getProjectId ( ) ;
3450 const request = {
3551 name : client . modelPath ( projectId , LOCATION , MODEL_ID ) ,
0 commit comments