Skip to content

Commit daa9a31

Browse files
authored
Merge branch 'main' into chore/datastore-cleanup
2 parents a30df4c + 450fac6 commit daa9a31

12 files changed

Lines changed: 150 additions & 94 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(

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
});

genai/count-tokens/test/counttoken-localtokenizer-compute-with-txt.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ const {assert} = require('chai');
1818
const {describe, it} = require('mocha');
1919

2020
const projectId = process.env.CAIP_PROJECT_ID;
21-
const sample = require('../counttoken-localtokenizer-compute-with-txt.js');
21+
const sample = require('../counttoken-compute-with-txt.js');
2222
const {delay} = require('../../test/util');
2323

2424
describe('counttoken-localtokenizer-compute-with-txt', () => {
2525
it('should return tokensInfo from text prompt', async function () {
2626
this.timeout(18000);
2727
this.retries(4);
2828
await delay(this.test);
29-
const output = await sample.countTokenLocalTokenizerCompute(projectId);
29+
const output = await sample.countTokens(projectId);
3030
assert(output.length > 0);
3131
});
3232
});

genai/count-tokens/test/counttoken-localtokenizer-with-txt.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ const {assert} = require('chai');
1818
const {describe, it} = require('mocha');
1919

2020
const projectId = process.env.CAIP_PROJECT_ID;
21-
const sample = require('../counttoken-localtokenizer-with-txt.js');
21+
const sample = require('../counttoken-with-txt.js');
2222
const {delay} = require('../../test/util');
2323

2424
describe('counttoken-localtokenizer-with-txt', () => {
2525
it('should return totalTokens from text prompt', async function () {
2626
this.timeout(18000);
2727
this.retries(4);
2828
await delay(this.test);
29-
const output = await sample.countTokenLocalTokenizer(projectId);
29+
const output = await sample.countTokens(projectId);
3030
assert(output > 0);
3131
});
3232
});

security-center/snippets/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"node": ">=16.0.0"
1010
},
1111
"scripts": {
12-
"test": "c8 mocha -p -j 2 --recursive --timeout 6000000 system-test/"
12+
"test": "c8 mocha --recursive --timeout 6000000 system-test/"
1313
},
1414
"license": "Apache-2.0",
1515
"dependencies": {

security-center/snippets/system-test/management_api/securityHealthAnalyticsCustomModule.test.js

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ const customModuleDisplayName =
3333
describe('security health analytics custom module', async () => {
3434
let data;
3535
const sharedModuleIds = [];
36+
const client = new SecurityCenterManagementClient();
3637

3738
before(async () => {
38-
const client = new SecurityCenterManagementClient();
3939
const EnablementState =
4040
protos.google.cloud.securitycentermanagement.v1
4141
.SecurityHealthAnalyticsCustomModule.EnablementState;
@@ -44,7 +44,8 @@ describe('security health analytics custom module', async () => {
4444
const parent = `organizations/${organizationId}/locations/${locationId}`;
4545
const name = `organizations/${organizationId}/locations/${locationId}/securityHealthAnalyticsCustomModules/custom_module`;
4646
const expr = {
47-
expression: `has(resource.rotationPeriod) && (resource.rotationPeriod > duration('2592000s'))`,
47+
expression:
48+
"has(resource.rotationPeriod) && (resource.rotationPeriod > duration('2592000s'))",
4849
};
4950
const resourceSelector = {
5051
resourceTypes: ['cloudkms.googleapis.com/CryptoKey'],
@@ -63,36 +64,59 @@ describe('security health analytics custom module', async () => {
6364
customConfig: customConfig,
6465
};
6566

66-
try {
67-
await new Promise(resolve => setTimeout(resolve, 3000));
68-
const [createResponse] =
69-
await client.createSecurityHealthAnalyticsCustomModule({
70-
parent: parent,
71-
securityHealthAnalyticsCustomModule:
72-
securityHealthAnalyticsCustomModule,
73-
});
74-
// extracts the custom module ID from the full name
75-
const customModuleId = createResponse.name.split('/').pop();
76-
data = {
77-
orgId: organizationId,
78-
customModuleId: customModuleId,
79-
customModuleName: createResponse.displayName,
80-
};
81-
console.log(
82-
'SecurityHealthAnalyticsCustomModule created : %j',
83-
createResponse
84-
);
85-
} catch (error) {
86-
console.error(
87-
'Error creating SecurityHealthAnalyticsCustomModule:',
88-
error
67+
let createResponse;
68+
const maxAttempts = 5;
69+
let attempt = 0;
70+
while (attempt < maxAttempts) {
71+
try {
72+
await new Promise(resolve => setTimeout(resolve, 3000));
73+
const [createSecurityResponse] =
74+
await client.createSecurityHealthAnalyticsCustomModule({
75+
parent: parent,
76+
securityHealthAnalyticsCustomModule:
77+
securityHealthAnalyticsCustomModule,
78+
});
79+
createResponse = createSecurityResponse;
80+
break;
81+
} catch (error) {
82+
if (error.code === 10) {
83+
attempt++;
84+
console.log(
85+
`Concurrent modification detected. Retrying creation (attempt ${attempt}/${maxAttempts})...`
86+
);
87+
await new Promise(resolve =>
88+
setTimeout(resolve, Math.pow(2, attempt) * 1000)
89+
);
90+
} else {
91+
console.error(
92+
'Fatal error creating SecurityHealthAnalyticsCustomModule:',
93+
error
94+
);
95+
throw error;
96+
}
97+
}
98+
}
99+
100+
if (!createResponse) {
101+
throw new Error(
102+
`Timeout: Failed to create custom module after ${maxAttempts} attempts due to concurrent modifications.`
89103
);
90104
}
105+
106+
// extracts the custom module ID from the full name
107+
const customModuleId = createResponse.name.split('/').pop();
108+
data = {
109+
orgId: organizationId,
110+
customModuleId: customModuleId,
111+
customModuleName: createResponse.displayName,
112+
};
113+
console.log(
114+
'SecurityHealthAnalyticsCustomModule created : %j',
115+
createResponse
116+
);
91117
});
92118

93119
after(async () => {
94-
const client = new SecurityCenterManagementClient();
95-
96120
if (sharedModuleIds.length > 0) {
97121
for (const moduleId of sharedModuleIds) {
98122
const name = `organizations/${organizationId}/locations/${locationId}/securityHealthAnalyticsCustomModules/${moduleId}`;
@@ -112,9 +136,11 @@ describe('security health analytics custom module', async () => {
112136
}
113137
}
114138
}
139+
await client.close();
115140
});
116141

117-
it('create security health analytics custom module', done => {
142+
it('create security health analytics custom module', function (done) {
143+
this.retries(3);
118144
const output = exec(
119145
`node management_api/createSecurityHealthAnalyticsCustomModule.js ${data.orgId} ${data.customModuleName} ${locationId}`
120146
);

0 commit comments

Comments
 (0)