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 8274076 commit c36eb47
Show file tree
Hide file tree
Showing 23 changed files with 98 additions and 68 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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "d77fcb7e4497ea7e1720518ba452504bdbe1a6a6de3a766745440129c8397e9e.zip"
"S3Key": "03b88dabbf9959e20788fc81687646e0ed6a152c994cfe69b0cd04169b3412b1.zip"
},
"Handler": "index.onEventHandler",
"Role": {
Expand Down Expand Up @@ -735,7 +735,7 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "d77fcb7e4497ea7e1720518ba452504bdbe1a6a6de3a766745440129c8397e9e.zip"
"S3Key": "03b88dabbf9959e20788fc81687646e0ed6a152c994cfe69b0cd04169b3412b1.zip"
},
"Handler": "index.isCompleteHandler",
"Role": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
16 changes: 8 additions & 8 deletions packages/aws-cdk-lib/cx-api/FEATURE_FLAGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,7 @@ shipped as part of the runtime environment.

*When enabled, will always use the arn for identifiers for CfnSourceApiAssociation in the GraphqlApi construct rather than id.* (fix)

When this feature flag is enabled, we use the IGraphqlApi ARN rather than ID when creating or updating CfnSourceApiAssociation in
When this feature flag is enabled, we use the IGraphqlApi ARN rather than ID when creating or updating CfnSourceApiAssociation in
the GraphqlApi construct. Using the ARN allows the association to support an association with a source api or merged api in another account.
Note that for existing source api associations created with this flag disabled, enabling the flag will lead to a resource replacement.

Expand Down Expand Up @@ -1200,7 +1200,7 @@ database cluster from a snapshot.

*When enabled, the CodeCommit source action is using the default branch name 'main'.* (fix)

When setting up a CodeCommit source action for the source stage of a pipeline, please note that the
When setting up a CodeCommit source action for the source stage of a pipeline, please note that the
default branch is 'master'.
However, with the activation of this feature flag, the default branch is updated to 'main'.

Expand Down Expand Up @@ -1378,7 +1378,7 @@ Other notifications that are not managed by this stack will be kept.
Currently, 'inputPath' and 'outputPath' from the TaskStateBase Props is being used under BedrockInvokeModelProps to define S3URI under 'input' and 'output' fields
of State Machine Task definition.

When this feature flag is enabled, specify newly introduced props 's3InputUri' and
When this feature flag is enabled, specify newly introduced props 's3InputUri' and
's3OutputUri' to populate S3 uri under input and output fields in state machine task definition for Bedrock invoke model.


Expand Down Expand Up @@ -1413,7 +1413,7 @@ When this feature flag is enabled, we will only grant the necessary permissions
*When enabled, initOptions.timeout and resourceSignalTimeout values will be summed together.* (fix)

Currently is both initOptions.timeout and resourceSignalTimeout are both specified in the options for creating an EC2 Instance,
only the value from 'resourceSignalTimeout' will be used.
only the value from 'resourceSignalTimeout' will be used.

When this feature flag is enabled, if both initOptions.timeout and resourceSignalTimeout are specified, the values will to be summed together.

Expand All @@ -1428,11 +1428,11 @@ When this feature flag is enabled, if both initOptions.timeout and resourceSigna

*When enabled, a Lambda authorizer Permission created when using GraphqlApi will be properly scoped with a SourceArn.* (fix)

Currently, when using a Lambda authorizer with an AppSync GraphQL API, the AWS CDK automatically generates the necessary AWS::Lambda::Permission
to allow the AppSync API to invoke the Lambda authorizer. This permission is overly permissive because it lacks a SourceArn, meaning
Currently, when using a Lambda authorizer with an AppSync GraphQL API, the AWS CDK automatically generates the necessary AWS::Lambda::Permission
to allow the AppSync API to invoke the Lambda authorizer. This permission is overly permissive because it lacks a SourceArn, meaning
it allows invocations from any source.

When this feature flag is enabled, the AWS::Lambda::Permission will be properly scoped with the SourceArn corresponding to the
When this feature flag is enabled, the AWS::Lambda::Permission will be properly scoped with the SourceArn corresponding to the
specific AppSync GraphQL API.


Expand All @@ -1446,7 +1446,7 @@ specific AppSync GraphQL API.

*When enabled, both `@aws-sdk` and `@smithy` packages will be excluded from the Lambda Node.js 18.x runtime to prevent version mismatches in bundled applications.* (fix)

Currently, when bundling Lambda functions with the non-latest runtime that supports AWS SDK JavaScript (v3), only the '@aws-sdk/*' packages are excluded by default.
Currently, when bundling Lambda functions with the non-latest runtime that supports AWS SDK JavaScript (v3), only the '@aws-sdk/*' packages are excluded by default.
However, this can cause version mismatches between the '@aws-sdk/*' and '@smithy/*' packages, as they are tightly coupled dependencies in AWS SDK v3.

When this feature flag is enabled, both '@aws-sdk/*' and '@smithy/*' packages will be excluded during the bundling process. This ensures that no mismatches
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
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ export class EvaluateCloudFormationTemplate {

if (Array.isArray(cfnExpression)) {
// Small arrays in practice
// eslint-disable-next-line @aws-cdk/promiseall-no-unbounded-parallelism
// eslint-disable-next-line @cdklabs/promiseall-no-unbounded-parallelism
return Promise.all(cfnExpression.map((expr) => this.evaluateCfnExpression(expr)));
}

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
2 changes: 1 addition & 1 deletion packages/aws-cdk/lib/api/hotswap/ecs-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export async function isHotswappableEcsServiceChange(
// Step 2 - update the services using that TaskDefinition to point to the new TaskDefinition Revision
// Forcing New Deployment and setting Minimum Healthy Percent to 0.
// As CDK HotSwap is development only, this seems the most efficient way to ensure all tasks are replaced immediately, regardless of original amount
// eslint-disable-next-line @aws-cdk/promiseall-no-unbounded-parallelism
// eslint-disable-next-line @cdklabs/promiseall-no-unbounded-parallelism
await Promise.all(
ecsServicesReferencingTaskDef.map(async (service) => {
const cluster = service.serviceArn.split('/')[1];
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
Loading

0 comments on commit c36eb47

Please sign in to comment.