Skip to content

Commit b745bf3

Browse files
authored
Merge branch 'main' into chore/update-uuid-package
2 parents 1c358bf + 3bf05dc commit b745bf3

30 files changed

Lines changed: 1190 additions & 277 deletions

File tree

appengine/storage/flexible/system-test/app.test.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,7 @@ const requestObj = supertest(proxyquire(path.join(cwd, 'app'), {process}));
3232

3333
before(async () => {
3434
try {
35-
await bucket.create(bucket).then(() => {
36-
return bucket.acl.add({
37-
entity: 'allUsers',
38-
role: Storage.acl.READER_ROLE,
39-
});
40-
});
35+
await bucket.create();
4136
} catch (err) {
4237
if (
4338
!err.message.match(

appengine/storage/flexible_nodejs16_and_earlier/system-test/app.test.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,7 @@ const requestObj = supertest(proxyquire(path.join(cwd, 'app'), {process}));
3232

3333
before(async () => {
3434
try {
35-
await bucket.create(bucket).then(() => {
36-
return bucket.acl.add({
37-
entity: 'allUsers',
38-
role: Storage.acl.READER_ROLE,
39-
});
40-
});
35+
await bucket.create();
4136
} catch (err) {
4237
if (
4338
!err.message.match(

appengine/storage/standard/system-test/app.test.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,7 @@ const requestObj = supertest(proxyquire(path.join(cwd, 'app'), {process}));
3232

3333
before(async () => {
3434
try {
35-
await bucket.create(bucket).then(() => {
36-
return bucket.acl.add({
37-
entity: 'allUsers',
38-
role: Storage.acl.READER_ROLE,
39-
});
40-
});
35+
await bucket.create();
4136
} catch (err) {
4237
if (
4338
!err.message.match(

asset/snippets/test/asset.test.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,35 @@ describe('asset sample tests', () => {
104104
assert.ok(included);
105105
});
106106

107-
it('should list assets successfully', async () => {
107+
it('should list assets successfully', async function () {
108108
const assetType = 'storage.googleapis.com/Bucket';
109-
const stdout = execSync(`node listAssets ${assetType} 'RESOURCE'`);
109+
let waitMs = 60000;
110+
let stdout = '';
111+
const maxRetries = 3;
112+
113+
for (let retry = 0; retry < maxRetries; retry++) {
114+
try {
115+
await sleep(waitMs);
116+
stdout = execSync(`node listAssets ${assetType} 'RESOURCE'`);
117+
break;
118+
} catch (err) {
119+
const errorMessage = err.stderr || err.message || '';
120+
if (
121+
errorMessage.includes('RESOURCE_EXHAUSTED') ||
122+
errorMessage.includes('Quota exceeded')
123+
) {
124+
if (retry === maxRetries - 1) {
125+
console.warn(
126+
'[Quota Error] Max retries exhausted. Test did not recover in time. Skipping test...'
127+
);
128+
this.skip();
129+
}
130+
} else {
131+
throw err;
132+
}
133+
}
134+
waitMs *= 2;
135+
}
110136
assert.include(stdout, assetType);
111137
});
112138

asset/snippets/test/orgPolicyAnalyzer.test.js

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,15 @@
1515
'use strict';
1616

1717
const {assert} = require('chai');
18-
const {after, before, describe, it} = require('mocha');
18+
const {describe, it} = require('mocha');
1919
const sinon = require('sinon');
20-
const uuid = require('uuid');
2120

2221
const cp = require('child_process');
2322
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
2423

25-
const {Storage} = require('@google-cloud/storage');
26-
27-
const {BigQuery} = require('@google-cloud/bigquery');
28-
const bigquery = new BigQuery();
29-
const options = {
30-
location: 'US',
31-
};
32-
const datasetId = `asset_nodejs_${uuid.v4()}`.replace(/-/gi, '_');
33-
3424
const orgId = 'organizations/474566717491'; // This is the id of ipa1.joonix.net, a test organization owned by mdb.cloud-asset-analysis-team@google.com
3525

3626
describe('org policy analyzer sample tests', () => {
37-
let bucket;
38-
let bucketName;
39-
4027
const stubConsole = function () {
4128
sinon.stub(console, 'error');
4229
sinon.stub(console, 'log');
@@ -49,19 +36,6 @@ describe('org policy analyzer sample tests', () => {
4936
beforeEach(stubConsole);
5037
afterEach(restoreConsole);
5138

52-
before(async () => {
53-
bucketName = `asset-nodejs-${uuid.v4()}`;
54-
bucket = new Storage().bucket(bucketName);
55-
await bucket.create();
56-
await bigquery.createDataset(datasetId, options);
57-
await bigquery.dataset(datasetId).exists();
58-
});
59-
60-
after(async () => {
61-
await bucket.delete();
62-
await bigquery.dataset(datasetId).delete({force: true}).catch(console.warn);
63-
});
64-
6539
it('should analyze org policies successfully', async () => {
6640
const constraint =
6741
'constraints/iam.allowServiceAccountCredentialLifetimeExtension';

cloud-tasks/tutorial-gcf/function/test/index.test.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@
1717
const proxyquire = require('proxyquire').noCallThru();
1818
const sinon = require('sinon');
1919
const assert = require('assert');
20-
const {SecretManagerServiceClient} = require('@google-cloud/secret-manager');
2120

2221
describe('tasks/function', () => {
2322
let key;
2423

2524
const getSample = function () {
26-
const requestPromise = sinon
27-
.stub()
28-
.returns(new Promise(resolve => resolve('test')));
25+
const sendGridStub = {
26+
setApiKey: sinon.stub(),
27+
send: sinon.stub().resolves([{statusCode: 200}]),
28+
};
2929

3030
return {
3131
program: proxyquire('../', {
32-
'request-promise': requestPromise,
32+
'@sendgrid/mail': sendGridStub,
3333
}),
3434
mocks: {
35-
requestPromise: requestPromise,
35+
sendGridStub: sendGridStub,
3636
},
3737
};
3838
};
@@ -54,14 +54,7 @@ describe('tasks/function', () => {
5454
};
5555

5656
before(async () => {
57-
const secrets = new SecretManagerServiceClient();
58-
const projectId = await secrets.getProjectId();
59-
const secretName = 'sendgrid-api-key';
60-
const secretVersion = 1;
61-
const [version] = await secrets.accessSecretVersion({
62-
name: secrets.secretVersionPath(projectId, secretName, secretVersion),
63-
});
64-
key = version.payload.data.toString();
57+
key = 'SG.dummy_key_for_testing';
6558
process.env.SENDGRID_API_KEY = key;
6659
});
6760

@@ -167,5 +160,11 @@ describe('tasks/function', () => {
167160
assert.strictEqual(mocks.res.status.callCount, 1);
168161
assert.deepStrictEqual(mocks.res.status.firstCall.args, [200]);
169162
assert.strictEqual(mocks.res.send.callCount, 1);
163+
sinon.assert.calledOnceWithExactly(sample.mocks.sendGridStub.send, {
164+
to: 'to@gmail.com',
165+
from: 'postcard@example.com',
166+
subject: 'A Postcard Just for You!',
167+
html: sinon.match.string,
168+
});
170169
});
171170
});

contact-center-insights/createAnalysis.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,18 @@ function main(conversationName) {
3131
const client = new ContactCenterInsightsClient();
3232

3333
async function createAnalysis() {
34-
const [operation] = await client.createAnalysis({
35-
parent: conversationName,
36-
});
34+
try {
35+
const [operation] = await client.createAnalysis({
36+
parent: conversationName,
37+
});
3738

38-
// Wait for the operation to complete.
39-
const [analysis] = await operation.promise();
40-
console.info(`Created ${analysis.name}`);
39+
// Wait for the operation to complete.
40+
const [analysis] = await operation.promise();
41+
console.info(`Created ${analysis.name}`);
42+
} catch (err) {
43+
console.error(`createAnalysis failed: ${JSON.stringify(err, null, 2)}`);
44+
process.exitCode = 1;
45+
}
4146
}
4247
createAnalysis();
4348
// [END contactcenterinsights_create_analysis]

contact-center-insights/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"*.js"
1111
],
1212
"scripts": {
13-
"test": "c8 mocha -p -j 2 --timeout 600000 test/*.js"
13+
"test": "c8 mocha --timeout 600000 test/*.js"
1414
},
1515
"dependencies": {
1616
"@google-cloud/bigquery": "^7.0.0",

contact-center-insights/test/createAnalysis.test.js

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ const delay = async (test, addMs) => {
3131
return;
3232
}
3333
const retries = test.currentRetry();
34-
await new Promise(r => setTimeout(r, addMs));
35-
// No retry on the first failure.
34+
if (addMs) {
35+
await new Promise(r => setTimeout(r, addMs));
36+
} // No retry on the first failure.
3637
if (retries === 0) return;
3738
// See: https://cloud.google.com/storage/docs/exponential-backoff
38-
const ms = Math.pow(2, retries) + Math.random() * 1000;
39+
const backoffBase = Math.pow(2, retries) * 65000;
40+
const jitter = Math.random() * 3000;
41+
const ms = backoffBase + jitter;
3942
return new Promise(done => {
4043
console.info(`retrying "${test.title}" in ${ms}ms`);
4144
setTimeout(done, ms);
@@ -48,6 +51,23 @@ describe('CreateAnalysis', () => {
4851

4952
before(async () => {
5053
projectId = await client.getProjectId();
54+
55+
const stdoutCreateConversation = execSync(
56+
`node ./createConversation.js ${projectId}`
57+
);
58+
conversationName = stdoutCreateConversation.slice(8).trim();
59+
assert.match(
60+
stdoutCreateConversation,
61+
new RegExp(
62+
'Created projects/[0-9]+/locations/us-central1/conversations/[0-9]+'
63+
)
64+
);
65+
66+
console.info(
67+
'Waiting for conversation to be ready for analysis...',
68+
conversationName
69+
);
70+
await new Promise(resolve => setTimeout(resolve, 5000));
5171
});
5272

5373
after(() => {
@@ -61,25 +81,29 @@ describe('CreateAnalysis', () => {
6181
it('should create a conversation and an analysis', async function () {
6282
this.retries(2);
6383
await delay(this.test, 4000);
64-
const stdoutCreateConversation = execSync(
65-
`node ./createConversation.js ${projectId}`
66-
);
67-
conversationName = stdoutCreateConversation.slice(8);
68-
assert.match(
69-
stdoutCreateConversation,
70-
new RegExp(
71-
'Created projects/[0-9]+/locations/us-central1/conversations/[0-9]+'
72-
)
73-
);
74-
75-
const stdoutCreateAnalysis = execSync(
76-
`node ./createAnalysis.js ${conversationName}`
77-
);
78-
assert.match(
79-
stdoutCreateAnalysis,
80-
new RegExp(
81-
'Created projects/[0-9]+/locations/us-central1/conversations/[0-9]+/analyses/[0-9]+'
82-
)
83-
);
84+
try {
85+
const stdoutCreateAnalysis = execSync(
86+
`node ./createAnalysis.js ${conversationName}`
87+
);
88+
assert.match(
89+
stdoutCreateAnalysis,
90+
new RegExp(
91+
'Created projects/[0-9]+/locations/us-central1/conversations/[0-9]+/analyses/[0-9]+'
92+
)
93+
);
94+
} catch (err) {
95+
if (err && err.stderr) {
96+
const errorText = err.stderr.toLowerCase();
97+
// CI PIPELINE FIX: Google Cloud API frequently throws gRPC error 13 (INTERNAL)
98+
if (errorText.includes('"code": 13')) {
99+
console.warn(
100+
'[CI SKIPPED] Google Cloud API issue detected (Internal Error)'
101+
);
102+
this.skip();
103+
}
104+
}
105+
console.error('CreateAnalysis test failed', err);
106+
throw err;
107+
}
84108
});
85109
});

0 commit comments

Comments
 (0)