diff --git a/contact-center-insights/test/createAnalysis.test.js b/contact-center-insights/test/createAnalysis.test.js index 98fbd5cf77..6d296dd7c7 100644 --- a/contact-center-insights/test/createAnalysis.test.js +++ b/contact-center-insights/test/createAnalysis.test.js @@ -22,9 +22,26 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const { ContactCenterInsightsClient, + // eslint-disable-next-line node/no-missing-require } = require('@google-cloud/contact-center-insights'); const client = new ContactCenterInsightsClient(); +const delay = async (test, addMs) => { + if (!test) { + return; + } + const retries = test.currentRetry(); + await new Promise(r => setTimeout(r, addMs)); + // No retry on the first failure. + if (retries === 0) return; + // See: https://cloud.google.com/storage/docs/exponential-backoff + const ms = Math.pow(2, retries) + Math.random() * 1000; + return new Promise(done => { + console.info(`retrying "${test.title}" in ${ms}ms`); + setTimeout(done, ms); + }); +}; + describe('CreateAnalysis', () => { let projectId; let conversationName; @@ -40,7 +57,10 @@ describe('CreateAnalysis', () => { }); }); - it('should create a conversation and an analysis', async () => { + // eslint-disable-next-line prefer-arrow-callback + it('should create a conversation and an analysis', async function () { + this.retries(2); + await delay(this.test, 4000); const stdoutCreateConversation = execSync( `node ./createConversation.js ${projectId}` ); diff --git a/contact-center-insights/test/exportToBigquery.test.js b/contact-center-insights/test/exportToBigquery.test.js index 29273d6e00..89d97432a3 100644 --- a/contact-center-insights/test/exportToBigquery.test.js +++ b/contact-center-insights/test/exportToBigquery.test.js @@ -36,6 +36,22 @@ const bigquery = new BigQuery(); const bigqueryDataset = generateUuid(); const bigqueryTable = generateUuid(); +const delay = async (test, addMs) => { + if (!test) { + return; + } + const retries = test.currentRetry(); + await new Promise(r => setTimeout(r, addMs)); + // No retry on the first failure. + if (retries === 0) return; + // See: https://cloud.google.com/storage/docs/exponential-backoff + const ms = Math.pow(2, retries) + Math.random() * 1000; + return new Promise(done => { + console.info(`retrying "${test.title}" in ${ms}ms`); + setTimeout(done, ms); + }); +}; + describe('ExportToBigQuery', () => { let projectId; let bigqueryProjectId; @@ -62,7 +78,9 @@ describe('ExportToBigQuery', () => { .catch(console.warn); }); - it('should export data to BigQuery', async () => { + it('should export data to BigQuery', async function () { + this.retries(2); + await delay(this.test, 4000); const stdout = execSync(`node ./exportToBigquery.js \ ${projectId} ${bigqueryProjectId} ${bigqueryDataset} ${bigqueryTable}`); assert.match(stdout, new RegExp('Exported data to BigQuery'));