Skip to content

Commit

Permalink
test: integ test for failed ecs hotswap
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwwright committed Nov 11, 2023
1 parent f19d26b commit f4a94bd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/@aws-cdk-testing/cli-integ/resources/cdk-apps/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,24 @@ class EcsHotswapStack extends cdk.Stack {
vpc,
});

// define a simple Fargate service
// allow stack to be used to test failed deployments
const image =
process.env.USE_INVALID_ECS_HOTSWAP_IMAGE == 'true'
? 'nginx:invalidtag'
: 'nginx:alpine';

// when testing failure, allow for desired count to be boosted
// to invoke circuit breaker threshold of 10 failed tasks as quickly as possible
// https://docs.aws.amazon.com/AmazonECS/latest/developerguide/deployment-circuit-breaker.html#failure-threshold
const desiredCount = process.env.USE_HIGH_ECS_TASK_COUNT == 'true' ? 10 : 1;

// deploy basic service
const taskDefinition = new ecs.FargateTaskDefinition(
this,
'task-definition'
);
taskDefinition.addContainer('nginx', {
image: ecs.ContainerImage.fromRegistry('nginx:alpine'),
image: ecs.ContainerImage.fromRegistry(image),
environment: {
SOME_VARIABLE: process.env.DYNAMIC_ECS_PROPERTY_VALUE ?? 'environment',
},
Expand All @@ -301,6 +312,8 @@ class EcsHotswapStack extends cdk.Stack {
cluster,
taskDefinition,
assignPublicIp: true, // required without NAT to pull image
circuitBreaker: { rollback: true },
desiredCount,
});

new cdk.CfnOutput(this, 'ClusterName', { value: cluster.clusterName });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,29 @@ integTest('hotswap deployment for ecs service waits for deployment to complete',

}));

integTest('hotswap deployment for ecs service detects failed deployment and errors', withDefaultFixture(async (fixture) => {
// GIVEN
await fixture.cdkDeploy('ecs-hotswap', {
modEnv: {
USE_HIGH_ECS_TASK_COUNT: 'true', // need to initially deploy high task count because hotswap deploy cannot modify task counts
},
});

// WHEN
const deployOutput = await fixture.cdkDeploy('ecs-hotswap', {
options: ['--hotswap'],
modEnv: {
USE_INVALID_ECS_HOTSWAP_IMAGE: 'true',
USE_HIGH_ECS_TASK_COUNT: 'true',
},
allowErrExit: true,
});

// THEN
expect(deployOutput).toContain(`❌ ${fixture.stackNamePrefix}-ecs-hotswap failed: ResourceNotReady: Resource is not in the state deploymentCompleted`);
expect(deployOutput).not.toContain('hotswapped!');
}));

async function listChildren(parent: string, pred: (x: string) => Promise<boolean>) {
const ret = new Array<string>();
for (const child of await fs.readdir(parent, { encoding: 'utf-8' })) {
Expand Down

0 comments on commit f4a94bd

Please sign in to comment.