Skip to content

Commit fe0e6e0

Browse files
authored
test: added an expo back off to prevent RESOURCE_EXHAUSTED exception (#630)
* test: added an expo back off to prevent RESOURCE_EXHAUSTED exception * modified comment * changed arrow func-> regular
1 parent eb9a57f commit fe0e6e0

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

dialogflow/resources/output.wav

83.4 KB
Binary file not shown.

dialogflow/system-test/list-session-entity-types.test.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const uuid = require('uuid');
2121
const dialogflow = require('@google-cloud/dialogflow');
2222
const exec = cmd => execSync(cmd, {encoding: 'utf8'});
2323

24+
const {delay} = require('./util');
25+
2426
describe('list session entity types', () => {
2527
const client = new dialogflow.EntityTypesClient();
2628
const sessionClient = new dialogflow.SessionEntityTypesClient();
@@ -64,7 +66,10 @@ describe('list session entity types', () => {
6466
await sessionClient.createSessionEntityType(sessionEntityTypeRequest);
6567
});
6668

67-
it('should List the Session Entity Type', async () => {
69+
it('should List the Session Entity Type', async function () {
70+
this.retries(5);
71+
await delay(this.test);
72+
6873
const output = exec(`${cmd} list-session-entity-types -s ${sessionId}`);
6974
assert.include(output, sessionId);
7075
assert.include(output, displayName);

dialogflow/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+
// DialogFlow tests sometimes run into 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)