Skip to content

Commit

Permalink
JavaScript (v3): SageMaker - Add afterAll hook in test to ensure clea…
Browse files Browse the repository at this point in the history
…nup on timeouts.
  • Loading branch information
cpyle0819 committed Mar 25, 2024
1 parent 3ab7738 commit 2ae64ae
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,27 @@ export class SageMakerPipelinesWkflw {
console.error(err);
throw err;
} finally {
// Run all of the clean up functions. If any fail, we log the error and continue.
// This ensures all clean up functions are run.
this.logger.logSeparator();
const doCleanUp = await this.prompter.confirm({
message: "Clean up resources?",
});
if (doCleanUp) {
for (let i = this.cleanUpFunctions.length - 1; i >= 0; i--) {
await retry(
{ intervalInMs: 1000, maxRetries: 60, swallowError: true },
this.cleanUpFunctions[i],
);
}
await this.cleanUp();
}
}
}

async cleanUp() {
// Run all of the clean up functions. If any fail, we log the error and continue.
// This ensures all clean up functions are run.
for (let i = this.cleanUpFunctions.length - 1; i >= 0; i--) {
await retry(
{ intervalInMs: 1000, maxRetries: 60, swallowError: true },
this.cleanUpFunctions[i],
);
}
}

async startWorkflow() {
this.logger.logSeparator(MESSAGES.greetingHeader);
await this.logger.log(MESSAGES.greeting);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { describe, test } from "vitest";
import { afterAll, describe, test } from "vitest";
import { SageMakerPipelinesWkflw } from "../scenarios/wkflw-sagemaker-geospatial-pipeline/SageMakerPipelinesWkflw.js";
import { Logger } from "@aws-doc-sdk-examples/lib/logger.js";
import { IAMClient } from "@aws-sdk/client-iam";
Expand All @@ -11,6 +11,15 @@ import { LambdaClient } from "@aws-sdk/client-lambda";
import { SQSClient } from "@aws-sdk/client-sqs";

describe("SageMaker geospatial pipeline workflow", () => {
/** @type {SageMakerPipelinesWkflw | undefined} */
let wkflw;

afterAll(async (ctx) => {
if (wkflw && ctx.result?.state === "fail") {
await wkflw.cleanUp();
}
});

test("should execute successfully", async () => {
const prompter = {
checkContinue() {
Expand All @@ -32,7 +41,7 @@ describe("SageMaker geospatial pipeline workflow", () => {
SQS: new SQSClient({ region: "us-west-2" }),
};

const wkflw = new SageMakerPipelinesWkflw(prompter, logger, clients);
wkflw = new SageMakerPipelinesWkflw(prompter, logger, clients);

await wkflw.run();
});
Expand Down
5 changes: 3 additions & 2 deletions javascriptv3/example_code/sagemaker/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import { defineConfig } from "vitest/config";

const ONE_SECOND = 1000;
const ONE_MINUTE = ONE_SECOND * 60;
const ONE_HOUR = ONE_MINUTE * 60;

export default defineConfig({
test: {
testTimeout: ONE_MINUTE * 45,
hookTimeout: 50000,
testTimeout: ONE_HOUR * 2,
hookTimeout: ONE_MINUTE * 30,
threads: false,
},
});

0 comments on commit 2ae64ae

Please sign in to comment.