Skip to content

Commit 3282f4e

Browse files
sararobcopybara-github
authored andcommitted
chore: Add system tests for agent engines module
PiperOrigin-RevId: 895367197
1 parent 912f684 commit 3282f4e

File tree

1 file changed

+57
-21
lines changed

1 file changed

+57
-21
lines changed

system_test/agent_engine_e2e_test.ts

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,29 @@ import {Client} from '../src/genai/client';
99
const PROJECT = process.env['GCLOUD_PROJECT'];
1010
const LOCATION = 'us-central1';
1111

12+
async function pollOperation(client: Client, operationName: string) {
13+
let isDone = false;
14+
let pollCount = 0;
15+
while (!isDone && pollCount < 40) {
16+
const status = await client.agentEnginesInternal.getAgentOperationInternal({
17+
operationName,
18+
});
19+
if (status.done) {
20+
return status;
21+
}
22+
pollCount++;
23+
await new Promise((resolve) => setTimeout(resolve, 5000));
24+
}
25+
throw new Error(
26+
`Operation ${operationName} did not complete within the timeout.`,
27+
);
28+
}
29+
1230
describe('agentEnginesInternal', () => {
1331
let client: Client;
1432
let agentEngineName: string|undefined;
15-
let operationName: string|undefined;
33+
let createOperationName: string|undefined;
34+
let updateOperationName: string|undefined;
1635

1736
beforeEach(() => {
1837
jasmine.DEFAULT_TIMEOUT_INTERVAL = 300000;
@@ -25,11 +44,11 @@ describe('agentEnginesInternal', () => {
2544
afterAll(async () => {
2645
// If the test failed during the create operation, try to recover
2746
// the resource name from the operation to cleanup.
28-
if (!agentEngineName && operationName) {
47+
if (!agentEngineName && createOperationName) {
2948
try {
3049
const status =
3150
await client.agentEnginesInternal.getAgentOperationInternal({
32-
operationName,
51+
operationName: createOperationName,
3352
});
3453
if (status.done && status.response?.name) {
3554
agentEngineName = status.response.name;
@@ -60,25 +79,42 @@ describe('agentEnginesInternal', () => {
6079
});
6180

6281
expect(createOp.name).toBeDefined();
63-
operationName = createOp.name;
64-
65-
// Poll for operation completion to get the Agent Engine resource name.
66-
let isDone = false;
67-
let pollCount = 0;
68-
while (!isDone && pollCount < 40) {
69-
const status =
70-
await client.agentEnginesInternal.getAgentOperationInternal({
71-
operationName: operationName!,
72-
});
73-
if (status.done) {
74-
isDone = true;
75-
agentEngineName = status.response?.name;
76-
} else {
77-
pollCount++;
78-
await new Promise((resolve) => setTimeout(resolve, 5000));
79-
}
80-
}
82+
createOperationName = createOp.name;
83+
84+
const status = await pollOperation(client, createOperationName!);
85+
agentEngineName = status.response?.name;
8186

8287
expect(agentEngineName).toBeDefined();
8388
});
89+
90+
it('should get an Agent Engine', async () => {
91+
const agentEngine = await client.agentEnginesInternal.getInternal({
92+
name: agentEngineName!,
93+
});
94+
expect(agentEngine.name).toBeDefined();
95+
expect(agentEngine.displayName).toEqual('test-agent-engine-sample');
96+
expect(agentEngine.labels).toEqual({'test-label': 'test-value'});
97+
});
98+
99+
it('should update an Agent Engine', async () => {
100+
const updateOp = await client.agentEnginesInternal.updateInternal({
101+
name: agentEngineName!,
102+
config: {
103+
displayName: 'test-agent-engine-updated',
104+
description: 'Updated from the Vertex JS SDK system tests',
105+
},
106+
});
107+
108+
expect(updateOp.name).toBeDefined();
109+
updateOperationName = updateOp.name;
110+
111+
const status = await pollOperation(client, updateOperationName!);
112+
113+
if (status.response) {
114+
expect(status.response.displayName)
115+
.toEqual(
116+
'test-agent-engine-updated',
117+
);
118+
}
119+
});
84120
});

0 commit comments

Comments
 (0)