Skip to content

Commit

Permalink
test: added an expo back off to prevent RESOURCE_EXHAUSTED exception (#…
Browse files Browse the repository at this point in the history
…630)

* test: added an expo back off to prevent RESOURCE_EXHAUSTED exception

* modified comment

* changed arrow func-> regular
  • Loading branch information
munkhuushmgl authored Jun 23, 2020
1 parent eb9a57f commit fe0e6e0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
Binary file modified dialogflow/resources/output.wav
Binary file not shown.
7 changes: 6 additions & 1 deletion dialogflow/system-test/list-session-entity-types.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const uuid = require('uuid');
const dialogflow = require('@google-cloud/dialogflow');
const exec = cmd => execSync(cmd, {encoding: 'utf8'});

const {delay} = require('./util');

describe('list session entity types', () => {
const client = new dialogflow.EntityTypesClient();
const sessionClient = new dialogflow.SessionEntityTypesClient();
Expand Down Expand Up @@ -64,7 +66,10 @@ describe('list session entity types', () => {
await sessionClient.createSessionEntityType(sessionEntityTypeRequest);
});

it('should List the Session Entity Type', async () => {
it('should List the Session Entity Type', async function () {
this.retries(5);
await delay(this.test);

const output = exec(`${cmd} list-session-entity-types -s ${sessionId}`);
assert.include(output, sessionId);
assert.include(output, displayName);
Expand Down
28 changes: 28 additions & 0 deletions dialogflow/system-test/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// DialogFlow tests sometimes run into quota issues, for which
// retrying with a backoff is a good strategy:
module.exports = {
async delay(test) {
const retries = test.currentRetry();
if (retries === 0) return; // no retry on the first failure.
// see: https://cloud.google.com/storage/docs/exponential-backoff:
const ms = Math.pow(2, retries) * 1000 + Math.random() * 2000;
return new Promise(done => {
console.info(`retrying "${test.title}" in ${ms}ms`);
setTimeout(done, ms);
});
},
};

0 comments on commit fe0e6e0

Please sign in to comment.