Skip to content

Commit 61c7509

Browse files
committed
ci: add durable integration test using capacity provider
1 parent 631b557 commit 61c7509

File tree

12 files changed

+386
-119
lines changed

12 files changed

+386
-119
lines changed

.github/workflows/integration-tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ jobs:
5252
GITHUB_EVENT_NAME: ${{ github.event_name }}
5353
GITHUB_EVENT_NUMBER: ${{ github.event.number }}
5454
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
55+
CAPACITY_PROVIDER_ARN: ${{ secrets.CAPACITY_PROVIDER_ARN }}
5556
run: node .github/workflows/scripts/integration-test/integration-test.js --deploy-only --runtime ${{ inputs.node-version }}
5657

5758
jest-integration-test:
@@ -95,5 +96,6 @@ jobs:
9596
LAMBDA_ENDPOINT: ${{ secrets.LAMBDA_ENDPOINT }}
9697
GITHUB_EVENT_NAME: ${{ github.event_name }}
9798
GITHUB_EVENT_NUMBER: ${{ github.event.number }}
99+
CAPACITY_PROVIDER_ARN: ${{ secrets.CAPACITY_PROVIDER_ARN }}
98100
run: |
99101
node .github/workflows/scripts/integration-test/integration-test.js --test-only --runtime ${{ inputs.node-version }}

.github/workflows/scripts/integration-test/integration-test.js

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ import {
1313
ResourceNotFoundException,
1414
} from "@aws-sdk/client-lambda";
1515

16+
import dotenv from "dotenv";
17+
const __filename = fileURLToPath(import.meta.url);
18+
const __dirname = dirname(__filename);
19+
20+
dotenv.config({
21+
path: join(__dirname, "../../../../.env"),
22+
});
23+
1624
// Colors for output
1725
const COLORS = {
1826
RED: "\x1b[0;31m",
@@ -33,9 +41,6 @@ const log = {
3341
console.error(`${COLORS.RED}[ERROR]${COLORS.NC} ${msg}`),
3442
};
3543

36-
const __filename = fileURLToPath(import.meta.url);
37-
const __dirname = dirname(__filename);
38-
3944
// Configuration
4045
const CONFIG = {
4146
AWS_REGION: process.env.AWS_REGION || "us-east-1",
@@ -62,20 +67,17 @@ class IntegrationTestRunner {
6267
this.cleanupOnExit = options.cleanupOnExit !== false;
6368
this.runtime = options.runtime;
6469
this.isGitHubActions = !!process.env.GITHUB_ACTIONS;
65-
/** @type {Record<string, string> | undefined} */
70+
/** @type {Record<string, {functionName: string, qualifier: string}> | undefined} */
6671
this.functionNameMap = undefined;
6772
/** @type {import('@aws-sdk/client-lambda').LambdaClient | null} */
6873
this.lambdaClient = null;
6974

7075
// Set up cleanup handler
7176
if (this.cleanupOnExit) {
72-
process.on("exit", () => this.cleanup());
7377
process.on("SIGINT", () => {
74-
this.cleanup();
7578
process.exit(130);
7679
});
7780
process.on("SIGTERM", () => {
78-
this.cleanup();
7981
process.exit(143);
8082
});
8183
}
@@ -140,7 +142,7 @@ class IntegrationTestRunner {
140142
}
141143

142144
const examples = this.getIntegrationExamples();
143-
/** @type {Record<string, string>} */
145+
/** @type {Record<string, {functionName: string, qualifier: string}>} */
144146
const functionNameMap = {};
145147

146148
// Get runtime suffix from argument or environment variable
@@ -173,15 +175,23 @@ class IntegrationTestRunner {
173175
}
174176

175177
const handlerFile = exampleHandler.replace(/\.handler$/, "");
176-
functionNameMap[handlerFile] = functionName;
178+
functionNameMap[handlerFile] = {
179+
functionName,
180+
qualifier: example.capacityProviderConfig
181+
? "$LATEST.PUBLISHED"
182+
: "$LATEST",
183+
};
177184
}
178185

179186
this.functionNameMap = functionNameMap;
180187
return functionNameMap;
181188
}
182189

183-
// Deploy Lambda functions
184-
async deployFunctions() {
190+
/**
191+
* Deploy Lambda functions
192+
* @param {string | undefined} testPattern
193+
*/
194+
async deployFunctions(testPattern) {
185195
log.info("Deploying Lambda functions...");
186196

187197
if (!process.env.AWS_ACCOUNT_ID) {
@@ -198,27 +208,28 @@ class IntegrationTestRunner {
198208

199209
// Extract handler file name from catalog
200210
const handlerFile = exampleHandler.replace(/\.handler$/, "");
201-
const functionName = functionNameMap[handlerFile];
211+
const { functionName } = functionNameMap[handlerFile];
202212

203-
log.info(`Deploying function: ${functionName} (handler: ${handlerFile})`);
213+
if (!testPattern || handlerFile.includes(testPattern)) {
214+
log.info(
215+
`Deploying function: ${functionName} (handler: ${handlerFile})`,
216+
);
204217

205-
// Package the function
206-
this.execCommand(`npm run package -- "${handlerFile}"`, {
207-
cwd: examplesDir,
208-
});
218+
// Package the function
219+
this.execCommand(`npm run package -- "${handlerFile}"`, {
220+
cwd: examplesDir,
221+
});
209222

210-
// Deploy using npm script with runtime parameter
211-
const deployCommand = `npm run deploy -- "${handlerFile}" '${functionName}' --runtime ${this.runtime}`;
223+
// Deploy using npm script with runtime parameter
224+
const deployCommand = `npm run deploy -- "${handlerFile}" '${functionName}' --runtime ${this.runtime}`;
212225

213-
this.execCommand(deployCommand, {
214-
cwd: examplesDir,
215-
});
216-
log.success(`Deployed function: ${functionName}`);
226+
this.execCommand(deployCommand, {
227+
cwd: examplesDir,
228+
});
229+
log.success(`Deployed function: ${functionName}`);
230+
}
217231
}
218232

219-
log.info("Function name map:");
220-
console.log(JSON.stringify(functionNameMap, null, 2));
221-
222233
if (this.isGitHubActions) {
223234
if (!process.env.GITHUB_OUTPUT) {
224235
throw new Error("Could not find GITHUB_OUTPUT environment variable");
@@ -239,9 +250,11 @@ class IntegrationTestRunner {
239250
const examplesDir = CONFIG.EXAMPLES_PACKAGE_PATH;
240251

241252
const functionsWithQualifier = Object.fromEntries(
242-
Object.entries(this.getFunctionNameMap()).map(([key, value]) => {
243-
return [key, `${value}:$LATEST`];
244-
}),
253+
Object.entries(this.getFunctionNameMap()).map(
254+
([key, { functionName, qualifier }]) => {
255+
return [key, `${functionName}:${qualifier}`];
256+
},
257+
),
245258
);
246259

247260
// Set additional environment variables
@@ -250,8 +263,6 @@ class IntegrationTestRunner {
250263
LAMBDA_ENDPOINT: CONFIG.LAMBDA_ENDPOINT,
251264
};
252265

253-
log.info("Running Jest integration tests with function map:");
254-
console.log(JSON.stringify(functionsWithQualifier, null, 2));
255266
log.info(`Lambda Endpoint: ${CONFIG.LAMBDA_ENDPOINT}`);
256267

257268
// Build test command with optional pattern
@@ -282,7 +293,7 @@ class IntegrationTestRunner {
282293
// Initialize Lambda client for cleanup
283294
const lambdaClient = this.initializeLambdaClient();
284295

285-
for (const functionName of Object.values(functionNameMap)) {
296+
for (const { functionName } of Object.values(functionNameMap)) {
286297
log.info(`Deleting function: ${functionName}`);
287298

288299
const deleteCommand = new DeleteFunctionCommand({
@@ -329,7 +340,7 @@ class IntegrationTestRunner {
329340
}
330341

331342
if (!testOnly) {
332-
await this.deployFunctions();
343+
await this.deployFunctions(testPattern);
333344
}
334345

335346
if (!deployOnly) {

package-lock.json

Lines changed: 7 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"@typescript-eslint/parser": "^8.44.0",
4747
"argparse": "^2.0.1",
4848
"concurrently": "^9.2.1",
49+
"dotenv": "^17.2.3",
4950
"eslint": "^9.29.0",
5051
"eslint-config-prettier": "^10.1.5",
5152
"eslint-plugin-jest": "^29.0.1",

packages/aws-durable-execution-sdk-js-examples/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@
4949
"@aws-sdk/client-dynamodb": "^3.943.0",
5050
"@aws-sdk/client-lambda": "^3.943.0",
5151
"@aws/durable-execution-sdk-js": "*",
52-
"@aws/durable-execution-sdk-js-testing": "*",
53-
"dotenv": "^17.2.3"
52+
"@aws/durable-execution-sdk-js-testing": "*"
5453
},
5554
"devDependencies": {
5655
"@aws/durable-execution-sdk-js-eslint-plugin": "*",
@@ -64,6 +63,7 @@
6463
"@types/js-yaml": "^4.0.9",
6564
"@types/node": "^22.13.5",
6665
"argparse": "^2.0.1",
66+
"dotenv": "^17.2.3",
6767
"eslint": "^9.23.0",
6868
"jest": "^30.2.0",
6969
"js-yaml": "^4.1.0",

0 commit comments

Comments
 (0)