Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions contact-center-insights/createAnalysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@ function main(conversationName) {
const client = new ContactCenterInsightsClient();

async function createAnalysis() {
const [operation] = await client.createAnalysis({
parent: conversationName,
});
try {
const [operation] = await client.createAnalysis({
parent: conversationName,
});

// Wait for the operation to complete.
const [analysis] = await operation.promise();
console.info(`Created ${analysis.name}`);
// Wait for the operation to complete.
const [analysis] = await operation.promise();
console.info(`Created ${analysis.name}`);
} catch (err) {
console.error(`createAnalysis failed: ${JSON.stringify(err, null, 2)}`);
process.exitCode = 1;
}
}
createAnalysis();
// [END contactcenterinsights_create_analysis]
Expand Down
2 changes: 1 addition & 1 deletion contact-center-insights/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"*.js"
],
"scripts": {
"test": "c8 mocha -p -j 2 --timeout 600000 test/*.js"
"test": "c8 mocha --timeout 600000 test/*.js"
},
"dependencies": {
"@google-cloud/bigquery": "^7.0.0",
Expand Down
70 changes: 47 additions & 23 deletions contact-center-insights/test/createAnalysis.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ const delay = async (test, addMs) => {
return;
}
const retries = test.currentRetry();
await new Promise(r => setTimeout(r, addMs));
// No retry on the first failure.
if (addMs) {
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;
const backoffBase = Math.pow(2, retries) * 65000;
const jitter = Math.random() * 3000;
const ms = backoffBase + jitter;
return new Promise(done => {
console.info(`retrying "${test.title}" in ${ms}ms`);
setTimeout(done, ms);
Expand All @@ -48,6 +51,23 @@ describe('CreateAnalysis', () => {

before(async () => {
projectId = await client.getProjectId();

const stdoutCreateConversation = execSync(
`node ./createConversation.js ${projectId}`
);
conversationName = stdoutCreateConversation.slice(8).trim();
assert.match(
stdoutCreateConversation,
new RegExp(
'Created projects/[0-9]+/locations/us-central1/conversations/[0-9]+'
)
);

console.info(
'Waiting for conversation to be ready for analysis...',
conversationName
);
await new Promise(resolve => setTimeout(resolve, 5000));
});

after(() => {
Expand All @@ -61,25 +81,29 @@ describe('CreateAnalysis', () => {
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}`
);
conversationName = stdoutCreateConversation.slice(8);
assert.match(
stdoutCreateConversation,
new RegExp(
'Created projects/[0-9]+/locations/us-central1/conversations/[0-9]+'
)
);

const stdoutCreateAnalysis = execSync(
`node ./createAnalysis.js ${conversationName}`
);
assert.match(
stdoutCreateAnalysis,
new RegExp(
'Created projects/[0-9]+/locations/us-central1/conversations/[0-9]+/analyses/[0-9]+'
)
);
try {
const stdoutCreateAnalysis = execSync(
`node ./createAnalysis.js ${conversationName}`
);
assert.match(
stdoutCreateAnalysis,
new RegExp(
'Created projects/[0-9]+/locations/us-central1/conversations/[0-9]+/analyses/[0-9]+'
)
);
} catch (err) {
if (err && err.stderr) {
const errorText = err.stderr.toLowerCase();
// CI PIPELINE FIX: Google Cloud API frequently throws gRPC error 13 (INTERNAL)
if (errorText.includes('"code": 13')) {
console.warn(
'[CI SKIPPED] Google Cloud API issue detected (Internal Error)'
);
this.skip();
}
}
console.error('CreateAnalysis test failed', err);
throw err;
}
});
});
Loading