Skip to content

Commit f30d158

Browse files
authored
test: another race condition (#369)
1 parent 78b1eb8 commit f30d158

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

automl/test/vision_object_detection_predict.test.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
'use strict';
1616

1717
const {assert} = require('chai');
18-
const {before, describe, it} = require('mocha');
18+
const {describe, it} = require('mocha');
1919
const {AutoMlClient} = require('@google-cloud/automl').v1;
2020

2121
const cp = require('child_process');
@@ -26,10 +26,26 @@ const MODEL_ID = 'IOD1656537412546854912';
2626
const PREDICT_REGION_TAG = 'vision_object_detection_predict';
2727
const 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+
2943
describe('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

Comments
 (0)