Skip to content

Commit a45067f

Browse files
committed
Remove deleteAndWaitCluster and use existing deleteCluster
1 parent 5ce466b commit a45067f

File tree

3 files changed

+22
-72
lines changed

3 files changed

+22
-72
lines changed

tests/integration/tools/atlas/atlasHelpers.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,11 @@ export async function assertClusterIsAvailable(
176176
}
177177
}
178178

179-
export async function deleteAndWaitCluster(
179+
export async function deleteCluster(
180180
session: Session,
181181
projectId: string,
182182
clusterName: string,
183-
pollingInterval: number = 1000,
184-
maxPollingIterations: number = 300
183+
shouldWaitTillClusterIsDeleted: boolean = false
185184
): Promise<void> {
186185
await session.apiClient.deleteCluster({
187186
params: {
@@ -192,16 +191,25 @@ export async function deleteAndWaitCluster(
192191
},
193192
});
194193

195-
for (let i = 0; i < maxPollingIterations; i++) {
196-
const isAvailable = await assertClusterIsAvailable(session, projectId, clusterName);
197-
if (!isAvailable) {
198-
return;
194+
if (!shouldWaitTillClusterIsDeleted) {
195+
return;
196+
}
197+
198+
while (true) {
199+
try {
200+
await session.apiClient.getCluster({
201+
params: {
202+
path: {
203+
groupId: projectId,
204+
clusterName,
205+
},
206+
},
207+
});
208+
await sleep(1000);
209+
} catch {
210+
break;
199211
}
200-
await sleep(pollingInterval);
201212
}
202-
throw new Error(
203-
`Cluster deletion timeout: ${clusterName} did not delete within ${maxPollingIterations} iterations`
204-
);
205213
}
206214

207215
export async function waitCluster(

tests/integration/tools/atlas/clusters.test.ts

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,12 @@
11
import type { Session } from "../../../../src/common/session.js";
22
import { expectDefined, getDataFromUntrustedContent, getResponseElements } from "../../helpers.js";
3-
import { describeWithAtlas, withProject, randomId, parseTable } from "./atlasHelpers.js";
3+
import { describeWithAtlas, withProject, randomId, parseTable, deleteCluster, waitCluster } from "./atlasHelpers.js";
44
import { afterAll, beforeAll, describe, expect, it } from "vitest";
55

66
function sleep(ms: number): Promise<void> {
77
return new Promise((resolve) => setTimeout(resolve, ms));
88
}
99

10-
async function deleteCluster(
11-
session: Session,
12-
projectId: string,
13-
clusterName: string,
14-
wait: boolean = false
15-
): Promise<void> {
16-
await session.apiClient.deleteCluster({
17-
params: {
18-
path: {
19-
groupId: projectId,
20-
clusterName,
21-
},
22-
},
23-
});
24-
25-
if (!wait) {
26-
return;
27-
}
28-
29-
while (true) {
30-
try {
31-
await session.apiClient.getCluster({
32-
params: {
33-
path: {
34-
groupId: projectId,
35-
clusterName,
36-
},
37-
},
38-
});
39-
await sleep(1000);
40-
} catch {
41-
break;
42-
}
43-
}
44-
}
45-
46-
async function waitCluster(
47-
session: Session,
48-
projectId: string,
49-
clusterName: string,
50-
check: (cluster: ClusterDescription20240805) => boolean | Promise<boolean>
51-
): Promise<void> {
52-
while (true) {
53-
const cluster = await session.apiClient.getCluster({
54-
params: {
55-
path: {
56-
groupId: projectId,
57-
clusterName,
58-
},
59-
},
60-
});
61-
if (await check(cluster)) {
62-
return;
63-
}
64-
await sleep(1000);
65-
}
66-
}
67-
6810
describeWithAtlas("clusters", (integration) => {
6911
withProject(integration, ({ getProjectId, getIpAddress }) => {
7012
const clusterName = "ClusterTest-" + randomId;

tests/integration/tools/atlas/performanceAdvisor.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import type { Session } from "../../../../src/common/session.js";
55
import { DEFAULT_LONG_RUNNING_TEST_WAIT_TIMEOUT_MS, expectDefined, getResponseElements } from "../../helpers.js";
6-
import { describeWithAtlas, withProject, randomId, deleteAndWaitCluster, waitCluster } from "./atlasHelpers.js";
6+
import { describeWithAtlas, withProject, randomId, waitCluster, deleteCluster } from "./atlasHelpers.js";
77
import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from "vitest";
88

99
describeWithAtlas("performanceAdvisor", (integration) => {
@@ -14,7 +14,7 @@ describeWithAtlas("performanceAdvisor", (integration) => {
1414
const projectId = getProjectId();
1515
if (projectId) {
1616
const session: Session = integration.mcpServer().session;
17-
await deleteAndWaitCluster(session, projectId, clusterName, 1000, 1200);
17+
await deleteCluster(session, projectId, clusterName);
1818
}
1919
}, DEFAULT_LONG_RUNNING_TEST_WAIT_TIMEOUT_MS);
2020

0 commit comments

Comments
 (0)