Skip to content

Commit 982f595

Browse files
authored
test: address flaky system test (#364)
1 parent 50e4a3c commit 982f595

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

dataproc/instantiateInlineWorkflowTemplate.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
/*eslint no-warning-comments: [0, { "terms": ["todo", "fixme"], "location": "anywhere" }]*/
2323

24-
function main(projectId = 'YOUR_PROJECT_ID', region = 'YOUR_REGION') {
24+
async function main(projectId = 'YOUR_PROJECT_ID', region = 'YOUR_REGION') {
2525
// [START dataproc_instantiate_inline_workflow_template]
2626
const dataproc = require('@google-cloud/dataproc');
2727

@@ -91,4 +91,7 @@ function main(projectId = 'YOUR_PROJECT_ID', region = 'YOUR_REGION') {
9191
instantiateInlineWorkflowTemplate();
9292
}
9393

94-
main(...process.argv.slice(2));
94+
main(...process.argv.slice(2)).catch(err => {
95+
console.error(err);
96+
process.exitCode = 1;
97+
});

dataproc/system-test/instantiateInlineWorkflowTemplate.test.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ const execSync = cmd =>
2626
encoding: 'utf-8',
2727
});
2828

29+
const {delay} = require('./util');
30+
2931
describe('instantiate an inline workflow template', () => {
30-
it('should instantiate an inline workflow template', async () => {
32+
it('should instantiate an inline workflow template', async function () {
33+
this.retries(4);
34+
await delay(this.test);
3135
const stdout = execSync(
3236
`node instantiateInlineWorkflowTemplate.js "${projectId}" "${region}"`
3337
);

dataproc/system-test/util.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// ML tests frequently run into concurrency and quota issues, for which
16+
// retrying with a backoff is a good strategy:
17+
module.exports = {
18+
async delay(test) {
19+
const retries = test.currentRetry();
20+
if (retries === 0) return; // no retry on the first failure.
21+
// see: https://cloud.google.com/storage/docs/exponential-backoff:
22+
const ms = Math.pow(2, retries) * 1000 + Math.random() * 2000;
23+
return new Promise(done => {
24+
console.info(`retrying "${test.title}" in ${ms}ms`);
25+
setTimeout(done, ms);
26+
});
27+
},
28+
};

0 commit comments

Comments
 (0)