Skip to content

Commit

Permalink
fix(e2e): clean up stale changesets (#3869)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe authored Aug 22, 2022
1 parent 2fa297a commit 22ede5a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/e2e/delete-stale-changesets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const { ListChangeSetsCommand, DeleteChangeSetCommand } = require("../../clients/client-cloudformation");

exports.deleteStaleChangesets = async (client, stackName) => {
const changesets = await client.send(
new ListChangeSetsCommand({
StackName: stackName,
})
);

try {
for (const changeset of changesets.Summaries) {
if (
changeset.Status === "FAILED" &&
changeset.StatusReason ===
`The submitted information didn't contain changes. Submit different information to create a change set.`
) {
console.log("Deleting stale changeset", changeset.ChangeSetId);
await new Promise((r) => setTimeout(r, 200));
await client.send(
new DeleteChangeSetCommand({
StackName: stackName,
ChangeSetName: changeset.ChangeSetId,
})
);
}
}
} catch(e) {
// non-blocking throttling error, potentially.
console.error(e);
}
};
9 changes: 9 additions & 0 deletions tests/e2e/ensure-test-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
waitUntilStackUpdateComplete,
waitUntilStackCreateComplete,
DescribeChangeSetCommand,
DeleteChangeSetCommand,
} = require("../../clients/client-cloudformation");

/**
Expand Down Expand Up @@ -51,6 +52,14 @@ exports.ensureTestStack = async (client, stackName, templateBody) => {
})
);
if (Status === "FAILED" && StatusReason.includes("The submitted information didn't contain changes")) {
await client
.send(
new DeleteChangeSetCommand({
StackName: stackName,
ChangeSetName: Id,
})
)
.catch(() => {}); // ignored
return;
}
throw e;
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/get-integ-test-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ const { STSClient, GetCallerIdentityCommand } = require("../../clients/client-st
const { CloudFormationClient, DescribeStackResourcesCommand } = require("../../clients/client-cloudformation");
const { S3ControlClient, ListMultiRegionAccessPointsCommand } = require("../../clients/client-s3-control");
const { ensureTestStack } = require("./ensure-test-stack");
const { deleteStaleChangesets } = require("./delete-stale-changesets");

exports.getIntegTestResources = async () => {
const cloudformation = new CloudFormationClient({ logger: console });
const region = await cloudformation.config.region();
const stackName = "SdkReleaseV3IntegTestResourcesStack";

await deleteStaleChangesets(cloudformation, stackName);
await ensureTestStack(
cloudformation,
stackName,
Expand Down

0 comments on commit 22ede5a

Please sign in to comment.