Skip to content

Commit 0844ff8

Browse files
authored
JavaScript (v3): Glue - Make clean up more robust. (#6829)
deleteDatabase wasn't being handled, leaving the test open to crashing before clean up was done. This handles that error. There was also a potential for objects in the S3 Bucket to not be fully deleted before trying to delete the bucket. I suspect this was causing issues leading to N stacks being created every run and not being torn down.
1 parent c656718 commit 0844ff8

File tree

3 files changed

+36
-46
lines changed

3 files changed

+36
-46
lines changed
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
{
22
"name": "@aws-doc-sdk-examples/glue",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "AWS SDK for JavaScript (v3) examples for AWS Glue",
55
"type": "module",
6-
"author": "corepyle@amazon.com",
6+
"author": "Corey Pyle <corepyle@amazon.com>",
77
"license": "Apache-2.0",
88
"scripts": {
99
"test": "vitest run **/*.unit.test.js",
1010
"integration-test": "vitest run **/*.integration.test.js --reporter=junit --outputFile=test_results/$npm_package_name.junit.xml"
1111
},
1212
"dependencies": {
13-
"@aws-doc-sdk-examples/lib": "^1.0.0",
14-
"@aws-sdk/client-glue": "^3.425.0",
13+
"@aws-doc-sdk-examples/lib": "^1.0.1",
14+
"@aws-sdk/client-glue": "^3.645.0",
1515
"chalk": "^5.3.0",
16-
"dotenv": "^16.3.1",
17-
"inquirer": "^9.2.11",
18-
"open": "^9.1.0"
16+
"dotenv": "^16.4.5",
17+
"inquirer": "^10.2.0",
18+
"open": "^10.1.0"
1919
},
2020
"devDependencies": {
21-
"@aws-sdk/client-cloudformation": "^3.204.0",
22-
"@aws-sdk/client-s3": "^3.204.0",
23-
"@vitest/coverage-c8": "^0.25.0",
24-
"vitest": "^1.6.0"
21+
"@aws-sdk/client-cloudformation": "^3.645.0",
22+
"@aws-sdk/client-s3": "^3.645.0",
23+
"vitest": "^2.0.5"
2524
}
2625
}

javascriptv3/example_code/glue/tests/glue-actions.integration.test.js

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
ListObjectsCommand,
1717
PutObjectCommand,
1818
S3Client,
19+
waitUntilObjectNotExists,
1920
} from "@aws-sdk/client-s3";
2021

2122
import { dirnameFromMetaUrl } from "@aws-doc-sdk-examples/lib/utils/util-fs.js";
@@ -42,7 +43,7 @@ config();
4243

4344
const dirname = dirnameFromMetaUrl(import.meta.url);
4445
const cdkAppPath = `${dirname}../../../../resources/cdk/glue_role_bucket/setup.yaml`;
45-
const stackName = `glue-test-stack-${Date.now()}`;
46+
const stackName = `glue-test-stack`;
4647
const fiveMinutesInMs = 5 * 60 * 1000; // 5 Minutes
4748
const fiveMinutesInSeconds = fiveMinutesInMs / 1000;
4849

@@ -83,9 +84,10 @@ const emptyS3Bucket = async (bucketName) => {
8384
const { Contents } = await client.send(listCommand);
8485

8586
await Promise.all(
86-
Contents.map(({ Key }) =>
87-
client.send(new DeleteObjectCommand({ Bucket: bucketName, Key })),
88-
),
87+
Contents.map(async ({ Key }) => {
88+
await client.send(new DeleteObjectCommand({ Bucket: bucketName, Key }));
89+
await waitUntilObjectNotExists({ client }, { Bucket: bucketName, Key });
90+
}),
8991
);
9092
};
9193

@@ -113,18 +115,14 @@ describe("actions", () => {
113115
}, fiveMinutesInMs);
114116

115117
afterAll(async () => {
116-
try {
117-
await emptyS3Bucket(bucketName).catch(console.error);
118-
await deleteTable("doc-example-database", "doc-example-csv").catch(
119-
console.error,
120-
);
121-
await deleteDatabase("doc-example-database");
122-
await deleteCrawler("s3-flight-data-crawler").catch(console.error);
123-
await deleteJob("flight_etl_job").catch(console.error);
124-
await deleteStack().catch(console.error);
125-
} catch (err) {
126-
console.error(err);
127-
}
118+
await emptyS3Bucket(bucketName).catch(console.error);
119+
await deleteTable("doc-example-database", "doc-example-csv").catch(
120+
console.error,
121+
);
122+
await deleteDatabase("doc-example-database").catch(console.error);
123+
await deleteCrawler("s3-flight-data-crawler").catch(console.error);
124+
await deleteJob("flight_etl_job").catch(console.error);
125+
await deleteStack().catch(console.error);
128126
}, fiveMinutesInMs);
129127

130128
const addPythonScriptToBucket = async () => {
@@ -207,20 +205,16 @@ describe("actions", () => {
207205
expect(JobRuns[0].JobName).toBe("flight_etl_job");
208206
};
209207

210-
it(
211-
"should run",
212-
async () => {
213-
await addPythonScriptToBucket();
214-
await testCreateCrawler();
215-
await testCreateJob(bucketName, roleName);
216-
await testListJobs();
217-
await testStartCrawler();
218-
await testGetDatabases();
219-
await testGetDatabase();
220-
await testGetTables();
221-
await testStartJobRun(bucketName);
222-
await testGetJobRuns();
223-
},
224-
{ timeout: fiveMinutesInMs * 5 },
225-
);
208+
it("should run", { timeout: fiveMinutesInMs * 5 }, async () => {
209+
await addPythonScriptToBucket();
210+
await testCreateCrawler();
211+
await testCreateJob(bucketName, roleName);
212+
await testListJobs();
213+
await testStartCrawler();
214+
await testGetDatabases();
215+
await testGetDatabase();
216+
await testGetTables();
217+
await testStartJobRun(bucketName);
218+
await testGetJobRuns();
219+
});
226220
});

javascriptv3/example_code/glue/vite.config.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,5 @@ export default defineConfig({
77
test: {
88
restoreMocks: true,
99
cache: false,
10-
coverage: {
11-
reporter: ["text", "html"],
12-
},
1310
},
1411
});

0 commit comments

Comments
 (0)