Skip to content

Commit

Permalink
fixed most integ tests - migrate and sam still issue
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealAmazonKendra committed Oct 8, 2024
1 parent cbbc235 commit 714b314
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 42 deletions.
1 change: 0 additions & 1 deletion packages/@aws-cdk-testing/cli-integ/lib/integ-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-console */
import * as fs from 'fs';
import * as path from 'path';
import { MemoryStream } from './corking';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2122,11 +2122,12 @@ integTest(
const functionName = response.Stacks?.[0].Outputs?.[0].OutputValue;

// THEN

// The deployment should not trigger a full deployment, thus the stack's status must remains
// "CREATE_COMPLETE"
expect(response.Stacks?.[0].StackStatus).toEqual('CREATE_COMPLETE');
expect(deployOutput).toContain(`Lambda Function '${functionName}' hotswapped!`);
// The entire string fails locally due to formatting. Making this test less specific
expect(deployOutput).toMatch(/hotswapped!/);
expect(deployOutput).toContain(functionName);
}),
);

Expand Down Expand Up @@ -2167,7 +2168,9 @@ integTest(
// The deployment should not trigger a full deployment, thus the stack's status must remains
// "CREATE_COMPLETE"
expect(response.Stacks?.[0].StackStatus).toEqual('CREATE_COMPLETE');
expect(deployOutput).toContain(`Lambda Function '${functionName}' hotswapped!`);
// The entire string fails locally due to formatting. Making this test less specific
expect(deployOutput).toMatch(/hotswapped!/);
expect(deployOutput).toContain(functionName);
} finally {
// Ensure cleanup in reverse order due to use of import/export
await fixture.cdkDestroy('lambda-hotswap');
Expand Down Expand Up @@ -2206,7 +2209,9 @@ integTest(
// The deployment should not trigger a full deployment, thus the stack's status must remains
// "CREATE_COMPLETE"
expect(response.Stacks?.[0].StackStatus).toEqual('CREATE_COMPLETE');
expect(deployOutput).toContain(`ECS Service '${serviceName}' hotswapped!`);
// The entire string fails locally due to formatting. Making this test less specific
expect(deployOutput).toMatch(/hotswapped!/);
expect(deployOutput).toContain(serviceName);
}),
);

Expand All @@ -2219,7 +2224,7 @@ integTest(
});

// WHEN
await fixture.cdkDeploy('ecs-hotswap', {
const deployOutput = await fixture.cdkDeploy('ecs-hotswap', {
options: ['--hotswap'],
modEnv: {
DYNAMIC_ECS_PROPERTY_VALUE: 'new value',
Expand All @@ -2245,14 +2250,16 @@ integTest(
}),
);
expect(describeServicesResponse.services?.[0].deployments).toHaveLength(1); // only one deployment present
expect(deployOutput).toMatch(/hotswapped!/);
}),
);

integTest(
'hotswap deployment for ecs service detects failed deployment and errors',
withExtendedTimeoutFixture(async (fixture) => {
// GIVEN
await fixture.cdkDeploy('ecs-hotswap');
// eslint-disable-next-line no-console
console.log(await fixture.cdkDeploy('ecs-hotswap', { verbose: true }));

// WHEN
const deployOutput = await fixture.cdkDeploy('ecs-hotswap', {
Expand All @@ -2261,10 +2268,11 @@ integTest(
USE_INVALID_ECS_HOTSWAP_IMAGE: 'true',
},
allowErrExit: true,
verbose: true,
});

const expectedSubstring = 'Resource is not in the state deploymentCompleted';

// THEN
const expectedSubstring = 'Resource is not in the expected state due to waiter status: TIMEOUT';
expect(deployOutput).toContain(expectedSubstring);
expect(deployOutput).not.toContain('hotswapped!');
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async function tryGetClusterSnapshotStatus(identifier: string): Promise<string |
});
return data.DBClusterSnapshots?.[0].Status;
} catch (err: any) {
if (err.code === 'DBClusterSnapshotNotFoundFault') {
if (err.name === 'DBClusterSnapshotNotFoundFault') {
return undefined;
}
throw err;
Expand Down
1 change: 0 additions & 1 deletion packages/@aws-cdk/custom-resource-handlers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"@aws-sdk/client-ecs": "3.632.0",
"@aws-sdk/client-ssm": "3.632.0",
"@aws-sdk/client-kinesis": "3.632.0",
"@aws-sdk/client-kms": "3.632.0",
"@aws-sdk/client-codepipeline": "3.632.0",
"@aws-sdk/client-redshift": "3.632.0",
"@aws-sdk/client-account": "3.632.0",
Expand Down
1 change: 0 additions & 1 deletion packages/aws-cdk/lib/api/aws-auth/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,6 @@ export interface ISSMClient {
}

export interface IStepFunctionsClient {
// listStateMachines(input: ListStateMachinesCommandInput): Promise<ListStateMachinesCommandOutput>;
updateStateMachine(input: UpdateStateMachineCommandInput): Promise<UpdateStateMachineCommandOutput>;
}

Expand Down
16 changes: 15 additions & 1 deletion packages/aws-cdk/lib/api/hotswap-deployments.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as cfn_diff from '@aws-cdk/cloudformation-diff';
import * as cxapi from '@aws-cdk/cx-api';
import { WaiterResult } from '@smithy/util-waiter';
import * as chalk from 'chalk';
import type { SDK, SdkProvider } from './aws-auth';
import type { DeployStackResult } from './deploy-stack';
Expand Down Expand Up @@ -416,7 +417,20 @@ async function applyHotswappableChange(sdk: SDK, hotswapOperation: HotswappableC

// if the SDK call fails, an error will be thrown by the SDK
// and will prevent the green 'hotswapped!' text from being displayed
await hotswapOperation.apply(sdk);
try {
await hotswapOperation.apply(sdk);
} catch (e: any) {
if (e.name === 'TimeoutError' || e.name === 'AbortError') {
const result: WaiterResult = JSON.parse(e.message);
const error = new Error([
`Resource is not in the expected state due to waiter status: ${result.state}`,
result.reason ? `${result.reason}.` : '',
].join('. '));
error.name = e.name;
throw error;
}
throw e;
}

for (const name of hotswapOperation.resourceNames) {
print(`${ICON} %s %s`, chalk.bold(name), chalk.green('hotswapped!'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ async function simpleRetry(fn: () => Promise<any>, numOfRetries: number, errorCo
try {
await fn();
} catch (error: any) {
if (error && error.code === errorCodeToRetry && numOfRetries > 0) {
if (error && error.name === errorCodeToRetry && numOfRetries > 0) {
await sleep(1000); // wait a whole second
await simpleRetry(fn, numOfRetries - 1, errorCodeToRetry);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ export class StackEventPoller {
private async doPoll(): Promise<ResourceEvent[]> {
const events: ResourceEvent[] = [];
try {
const eventList = await this.cfn.describeStackEvents({ StackName: this.props.stackName });
const eventList = await this.cfn.describeStackEvents({
StackName: this.props.stackName,
});
for (const event of eventList) {
// Event from before we were interested in 'em
if (this.props.startTime !== undefined && event.Timestamp!.valueOf() < this.props.startTime) {
Expand Down Expand Up @@ -130,7 +132,7 @@ export class StackEventPoller {
}
}
} catch (e: any) {
if (!(e.code === 'ValidationError' && e.message === `Stack [${this.props.stackName}] does not exist`)) {
if (!(e.name === 'ValidationError' && e.message === `Stack [${this.props.stackName}] does not exist`)) {
throw e;
}
}
Expand Down
32 changes: 18 additions & 14 deletions packages/aws-cdk/lib/cdk-toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ export class CdkToolkit {
// It has to be exactly this string because an integration test tests for
// "bold(stackname) failed: ResourceNotReady: <error>"
throw new Error(
[`❌ ${chalk.bold(stack.stackName)} failed:`, ...(e.code ? [`${e.code}:`] : []), e.message].join(' '),
[`❌ ${chalk.bold(stack.stackName)} failed:`, ...(e.name ? [`${e.name}:`] : []), e.message].join(' '),
);
} finally {
if (options.cloudWatchLogMonitor) {
Expand Down Expand Up @@ -908,19 +908,23 @@ export class CdkToolkit {
const limit = pLimit(20);

// eslint-disable-next-line @aws-cdk/promiseall-no-unbounded-parallelism
await Promise.all(environments.map((environment) => limit(async () => {
success(' ⏳ Bootstrapping environment %s...', chalk.blue(environment.name));
try {
const result = await bootstrapper.bootstrapEnvironment(environment, this.props.sdkProvider, options);
const message = result.noOp
? ' ✅ Environment %s bootstrapped (no changes).'
: ' ✅ Environment %s bootstrapped.';
success(message, chalk.blue(environment.name));
} catch (e) {
error(' ❌ Environment %s failed bootstrapping: %s', chalk.blue(environment.name), e);
throw e;
}
})));
await Promise.all(
environments.map((environment) =>
limit(async () => {
success(' ⏳ Bootstrapping environment %s...', chalk.blue(environment.name));
try {
const result = await bootstrapper.bootstrapEnvironment(environment, this.props.sdkProvider, options);
const message = result.noOp
? ' ✅ Environment %s bootstrapped (no changes).'
: ' ✅ Environment %s bootstrapped.';
success(message, chalk.blue(environment.name));
} catch (e) {
error(' ❌ Environment %s failed bootstrapping: %s', chalk.blue(environment.name), e);
throw e;
}
}),
),
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"@smithy/types": "3.5.0",
"@smithy/util-retry": "3.0.7",
"@smithy/util-stream": "3.1.9",
"@smithy/util-waiter": "^3.1.6",
"@smithy/util-waiter": "3.1.6",
"camelcase": "^6",
"cdk-assets": "3.0.0-rc.32",
"cdk-from-cfn": "^0.162.0",
Expand Down
7 changes: 5 additions & 2 deletions packages/aws-cdk/test/api/fake-sts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ export class FakeSts {
private decodeMapFromRequestBody(parameter: string, body: Record<string, string>): Tag[] {
return Object.entries(body)
.filter(([key, _]) => key.startsWith(`${parameter}.member.`) && key.endsWith('.Key'))
.map(([key, tagKey]) => ({ Key: tagKey, Value: body[`${parameter}.member.${key.split('.')[2]}.Value`] }));
.map(([key, tagKey]) => ({
Key: tagKey,
Value: body[`${parameter}.member.${key.split('.')[2]}.Value`],
}));
}

/**
Expand Down Expand Up @@ -281,7 +284,7 @@ export class FakeSts {
const failureRequested = s.match(/<FAIL:([^>]+)>/);
if (failureRequested) {
const err = new Error(`STS failing by user request: ${failureRequested[1]}`);
(err as any).code = failureRequested[1];
(err as any).name = failureRequested[1];
throw err;
}
}
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6204,6 +6204,15 @@
"@smithy/util-buffer-from" "^3.0.0"
tslib "^2.6.2"

"@smithy/util-waiter@3.1.6", "@smithy/util-waiter@^3.1.6":
version "3.1.6"
resolved "https://registry.npmjs.org/@smithy/util-waiter/-/util-waiter-3.1.6.tgz#c65870d0c802e33b96112fac5c4471b3bf2eeecb"
integrity sha512-xs/KAwWOeCklq8aMlnpk25LgxEYHKOEodfjfKclDMLcBJEVEKzDLxZxBQyztcuPJ7F54213NJS8PxoiHNMdItQ==
dependencies:
"@smithy/abort-controller" "^3.1.5"
"@smithy/types" "^3.5.0"
tslib "^2.6.2"

"@smithy/util-waiter@^3.1.2":
version "3.1.3"
resolved "https://registry.npmjs.org/@smithy/util-waiter/-/util-waiter-3.1.3.tgz#a633257cc65f83cf5714a0f66665070868c3aa91"
Expand All @@ -6213,15 +6222,6 @@
"@smithy/types" "^3.4.0"
tslib "^2.6.2"

"@smithy/util-waiter@^3.1.6":
version "3.1.6"
resolved "https://registry.npmjs.org/@smithy/util-waiter/-/util-waiter-3.1.6.tgz#c65870d0c802e33b96112fac5c4471b3bf2eeecb"
integrity sha512-xs/KAwWOeCklq8aMlnpk25LgxEYHKOEodfjfKclDMLcBJEVEKzDLxZxBQyztcuPJ7F54213NJS8PxoiHNMdItQ==
dependencies:
"@smithy/abort-controller" "^3.1.5"
"@smithy/types" "^3.5.0"
tslib "^2.6.2"

"@szmarczak/http-timer@^5.0.1":
version "5.0.1"
resolved "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-5.0.1.tgz#c7c1bf1141cdd4751b0399c8fc7b8b664cd5be3a"
Expand Down

0 comments on commit 714b314

Please sign in to comment.