diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationQueryHandler.java index 0d8f8844f4..ecf1635146 100644 --- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationQueryHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationQueryHandler.java @@ -24,7 +24,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; -import java.util.concurrent.Future; /** * Handles CloudFormation Query-protocol API calls (form-encoded POST, XML response). @@ -119,20 +118,23 @@ public class CloudFormationQueryHandler { List capabilities = extractList(params, "Capabilities.member."); Map tags = extractTags(params); - cfnService.createChangeSet(stackName, "initial-create", "CREATE", - templateBody, templateUrl, parameters, capabilities, tags, region); - awaitExecution(cfnService.executeChangeSet(stackName, "initial-create", region)); - - if (Boolean.parseBoolean(params.getFirst("EnableTerminationProtection"))) { - // CreateStackInput carries the same member; honor it so the stack is created protected. - cfnService.updateTerminationProtection(stackName, true, region); + boolean terminationProtection = Boolean.parseBoolean(params.getFirst("EnableTerminationProtection")); + ChangeSet initial = cfnService.createChangeSetForCreateStack(stackName, "initial-create", + templateBody, templateUrl, parameters, capabilities, tags, region, + terminationProtection); + try { + cfnService.executeChangeSet(initial.getStackId(), initial.getChangeSetId(), region); + } catch (AwsException e) { + if (terminationProtection) { + cfnService.clearProtectionAfterRejectedCreate(stackName, initial, region); + } + throw e; } - Stack stack = cfnService.describeStacks(stackName, region).get(0); String xml = new XmlBuilder() .start("CreateStackResponse", CF_NS) .start("CreateStackResult") - .elem("StackId", stack.getStackId()) + .elem("StackId", initial.getStackId()) .end("CreateStackResult") .raw(AwsQueryResponse.responseMetadata()) .end("CreateStackResponse") @@ -165,13 +167,12 @@ public class CloudFormationQueryHandler { cfnService.deleteChangeSet(stackName, cs.getChangeSetName(), region); return xmlError("ValidationError", "No updates are to be performed.", 400); } - awaitExecution(cfnService.executeChangeSet(stackName, cs.getChangeSetName(), region)); + cfnService.executeChangeSet(cs.getStackId(), cs.getChangeSetId(), region); - Stack stack = cfnService.describeStacks(stackName, region).get(0); String xml = new XmlBuilder() .start("UpdateStackResponse", CF_NS) .start("UpdateStackResult") - .elem("StackId", stack.getStackId()) + .elem("StackId", cs.getStackId()) .end("UpdateStackResult") .raw(AwsQueryResponse.responseMetadata()) .end("UpdateStackResponse") @@ -1134,14 +1135,6 @@ public class CloudFormationQueryHandler { xml.end("Parameters"); } - private void awaitExecution(Future future) { - try { - future.get(); - } catch (Exception e) { - LOG.warnv("Stack execution failed: {0}", e.getMessage()); - } - } - private Response xmlError(String code, String message, int status) { String xml = new XmlBuilder() .start("ErrorResponse", CF_NS) diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java index 686d951d2a..4c440191ff 100644 --- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java +++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java @@ -234,6 +234,25 @@ public class CloudFormationService implements ResourceProvider { return stack; } + public void clearProtectionAfterRejectedCreate(String stackName, ChangeSet initial, String region) { + String accountId = currentAccount(); + stacks.computeIfPresent(stackKey(accountId, stackName, region), (key, stack) -> { + ChangeSet current = stack.getChangeSets().get(initial.getChangeSetName()); + if (stack.getStackId().equals(initial.getStackId()) + && "REVIEW_IN_PROGRESS".equals(stack.getStatus()) + && (current == null && stack.getChangeSets().isEmpty() + || current != null && current.getChangeSetId().equals(initial.getChangeSetId()) + && ("AVAILABLE".equals(current.getExecutionStatus()) + || "UNAVAILABLE".equals(current.getExecutionStatus()))) + && !runningExecutions.containsKey(stack.getStackId())) { + stack.setEnableTerminationProtection(false); + // Keep this rare rejection cleanup ordered before a concurrent delete unpersists it. + persistStack(stack); + } + return stack; + }); + } + // ── DescribeStacks ──────────────────────────────────────────────────────── public List describeStacks(String stackName, String region) { @@ -347,7 +366,7 @@ public class CloudFormationService implements ResourceProvider { } String previousTemplate = previousTemplateOf(stack); created = createChangeSet(stackName, changeSetName, "UPDATE", previousTemplate, null, - parameters, capabilities, tags, region, currentAccount(), false, true); + parameters, capabilities, tags, region, currentAccount(), false, true, false); } return created; } @@ -365,7 +384,17 @@ public class CloudFormationService implements ResourceProvider { Map parameters, List capabilities, Map tags, String region) { return createChangeSet(stackName, changeSetName, changeSetType, templateBody, templateUrl, - parameters, capabilities, tags, region, regionResolver.getAccountId(), false, false); + parameters, capabilities, tags, region, regionResolver.getAccountId(), false, false, false); + } + + public ChangeSet createChangeSetForCreateStack(String stackName, String changeSetName, + String templateBody, String templateUrl, + Map parameters, List capabilities, + Map tags, String region, + boolean enableTerminationProtection) { + return createChangeSet(stackName, changeSetName, "CREATE", templateBody, templateUrl, + parameters, capabilities, tags, region, regionResolver.getAccountId(), false, false, + enableTerminationProtection); } /** @@ -389,7 +418,7 @@ public class CloudFormationService implements ResourceProvider { Map parameters, List capabilities, Map tags, String region) { return createChangeSet(stackName, changeSetName, changeSetType, templateBody, templateUrl, - parameters, capabilities, tags, region, regionResolver.getAccountId(), true, false); + parameters, capabilities, tags, region, regionResolver.getAccountId(), true, false, false); } /** @@ -407,14 +436,15 @@ public class CloudFormationService implements ResourceProvider { Map parameters, List capabilities, Map tags, String region, String accountId) { return createChangeSet(stackName, changeSetName, changeSetType, templateBody, templateUrl, - parameters, capabilities, tags, region, accountId, false, false); + parameters, capabilities, tags, region, accountId, false, false, false); } private ChangeSet createChangeSet(String stackName, String changeSetName, String changeSetType, String templateBody, String templateUrl, Map parameters, List capabilities, Map tags, String region, String accountId, - boolean attachToReviewInProgressStack, boolean fromPreviousTemplate) { + boolean attachToReviewInProgressStack, boolean fromPreviousTemplate, + boolean enableTerminationProtection) { String resolvedTemplate = resolveTemplate(templateBody, templateUrl); requireValidTemplate(resolvedTemplate); boolean isCreateType = "CREATE".equalsIgnoreCase(changeSetType); @@ -511,6 +541,7 @@ public class CloudFormationService implements ResourceProvider { target = newStack(stackName, createdStackId != null ? createdStackId : newStackId(stackName, region, accountId), region, accountId); + target.setEnableTerminationProtection(enableTerminationProtection); if (tags != null) target.getTags().putAll(tags); // A CREATE change set puts a brand-new stack into REVIEW_IN_PROGRESS. Record the // matching stack-level event (as AWS and LocalStack do) so DescribeStackEvents is @@ -1289,6 +1320,9 @@ public class CloudFormationService implements ResourceProvider { cs.setExecutionStatus(status != null && (status.contains("ROLLBACK") || status.endsWith("_FAILED")) ? "EXECUTE_FAILED" : "EXECUTE_COMPLETE"); persistStack(stack); + } catch (RuntimeException | Error e) { + LOG.errorv(e, "Stack {0} execution aborted unexpectedly", stack.getStackName()); + throw e; } finally { endExecution(stack, claimed.done(), region, accountId); } @@ -1322,6 +1356,7 @@ public class CloudFormationService implements ResourceProvider { } done.complete(null); } catch (RuntimeException e) { + LOG.errorv(e, "Stack {0} execution cleanup failed", stack.getStackName()); done.completeExceptionally(e); } } diff --git a/src/test/java/io/github/hectorvent/floci/core/common/PartitionArnMintingIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/core/common/PartitionArnMintingIntegrationTest.java index c37fae2aca..bcd5b588bb 100644 --- a/src/test/java/io/github/hectorvent/floci/core/common/PartitionArnMintingIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/core/common/PartitionArnMintingIntegrationTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.core.common; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.github.hectorvent.floci.testing.PartitionCleanup; import io.github.hectorvent.floci.testing.PartitionMatrix; import io.github.hectorvent.floci.testing.PartitionMatrix.PartitionCase; @@ -67,6 +68,8 @@ class PartitionArnMintingIntegrationTest { .formParam("StackName", stackName) .when().post("/")); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", + PartitionMatrix.sigV4Auth(region, "cloudformation")); given() .header("Authorization", PartitionMatrix.sigV4Auth(region, "cloudformation")) .contentType("application/x-www-form-urlencoded") diff --git a/src/test/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingLaunchConfigurationMetadataIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingLaunchConfigurationMetadataIntegrationTest.java index f9101e25d9..92c7b452e4 100644 --- a/src/test/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingLaunchConfigurationMetadataIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingLaunchConfigurationMetadataIntegrationTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.autoscaling; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.github.hectorvent.floci.testing.EnforcementFixtures; import io.quarkus.test.junit.QuarkusTest; import io.restassured.response.ValidatableResponse; @@ -164,6 +165,7 @@ class AutoScalingLaunchConfigurationMetadataIntegrationTest { """.formatted(name); request("cloudformation", "CreateStack").formParam("StackName", name) .formParam("TemplateBody", template).post("/").then().statusCode(200); + CfnStackWaits.awaitStatus(name, "CREATE_COMPLETE", EnforcementFixtures.auth(ACCOUNT, "cloudformation")); } else { request("autoscaling", "CreateLaunchConfiguration") .formParam("LaunchConfigurationName", name).formParam("ImageId", "ami-amazonlinux2023") @@ -205,6 +207,7 @@ class AutoScalingLaunchConfigurationMetadataIntegrationTest { .formParam("Parameters.member.1.ParameterKey", "Strict") .formParam("Parameters.member.1.ParameterValue", strict ? "yes" : "no") .post("/").then().statusCode(200); + CfnStackWaits.awaitStatus(name, "CREATE_COMPLETE", EnforcementFixtures.auth(ACCOUNT, "cloudformation")); ValidatableResponse described = describeLaunchConfiguration(name); if (strict) { described.body(LAUNCH_CONFIGURATION + ".MetadataOptions.HttpTokens", equalTo("required")) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/AcmCfnIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/AcmCfnIntegrationTest.java index 8f0927fae0..f0606c3771 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/AcmCfnIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/AcmCfnIntegrationTest.java @@ -206,6 +206,8 @@ class AcmCfnIntegrationTest { } private static String describeStacks(String stack, String expectedStatus) { + CfnStackWaits.StackState state = CfnStackWaits.awaitTerminal(stack, CFN_AUTH); + assertEquals(expectedStatus, state.status(), state.reason()); return given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/ApiGatewayCfnMockCorsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/ApiGatewayCfnMockCorsIntegrationTest.java index c39c40d5b5..e4aa6dd122 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/ApiGatewayCfnMockCorsIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/ApiGatewayCfnMockCorsIntegrationTest.java @@ -60,6 +60,7 @@ class ApiGatewayCfnMockCorsIntegrationTest { .formParam("TemplateBody", TEMPLATE) .when().post("/").then().statusCode(200); try { + CfnStackWaits.awaitStatus(STACK, "CREATE_COMPLETE"); String xml = given().contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") .formParam("StackName", STACK) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/ApiGatewayDomainCfnIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/ApiGatewayDomainCfnIntegrationTest.java index f298c4ab0c..028369f440 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/ApiGatewayDomainCfnIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/ApiGatewayDomainCfnIntegrationTest.java @@ -278,6 +278,7 @@ class ApiGatewayDomainCfnIntegrationTest { } private static String describeStacks(String stack, String expectedStatus) { + CfnStackWaits.awaitStatus(stack, expectedStatus, CFN_AUTH); return given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/ApiGatewayGatewayResponseCfnIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/ApiGatewayGatewayResponseCfnIntegrationTest.java index e75fa3417e..da5d27fe18 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/ApiGatewayGatewayResponseCfnIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/ApiGatewayGatewayResponseCfnIntegrationTest.java @@ -146,6 +146,7 @@ class ApiGatewayGatewayResponseCfnIntegrationTest { } private static String describeStacks(String expectedStatus) { + CfnStackWaits.awaitStatus(STACK, expectedStatus, CFN_AUTH); return given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/ApiGatewayUsagePlanCfnIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/ApiGatewayUsagePlanCfnIntegrationTest.java index 878b1338d8..a807f766ff 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/ApiGatewayUsagePlanCfnIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/ApiGatewayUsagePlanCfnIntegrationTest.java @@ -191,6 +191,7 @@ class ApiGatewayUsagePlanCfnIntegrationTest { } private static String describeStacks(String expectedStatus) { + CfnStackWaits.awaitStatus(STACK, expectedStatus, CFN_AUTH); return given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/AppSyncCfnIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/AppSyncCfnIntegrationTest.java index 1e2b4fd4a2..47c05d7143 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/AppSyncCfnIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/AppSyncCfnIntegrationTest.java @@ -505,6 +505,7 @@ class AppSyncCfnIntegrationTest { } private static String describeStacks(String stackName, String expectedStatus) { + CfnStackWaits.awaitStatus(stackName, expectedStatus, CFN_AUTH); return cfn("DescribeStacks", stackName).header("Authorization", CFN_AUTH) .when().post("/").then().statusCode(200) .body(containsString("" + expectedStatus + "")) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/AutoScalingScalingPolicyCfnIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/AutoScalingScalingPolicyCfnIntegrationTest.java index 36ba451091..03bd496e73 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/AutoScalingScalingPolicyCfnIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/AutoScalingScalingPolicyCfnIntegrationTest.java @@ -166,6 +166,8 @@ class AutoScalingScalingPolicyCfnIntegrationTest { } private static String describeStacks(String expectedStatus) { + CfnStackWaits.StackState state = CfnStackWaits.awaitTerminal(STACK, CFN_AUTH); + assertEquals(expectedStatus, state.status(), state.reason()); return given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/AwsIncludeIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/AwsIncludeIntegrationTest.java index db62a64e59..1faeb71249 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/AwsIncludeIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/AwsIncludeIntegrationTest.java @@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.cloudformation; import com.fasterxml.jackson.databind.ObjectMapper; import io.github.hectorvent.floci.services.s3.S3Service; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; import io.quarkus.test.junit.QuarkusTest; import jakarta.inject.Inject; @@ -113,6 +114,7 @@ class AwsIncludeIntegrationTest { .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -166,6 +168,7 @@ class AwsIncludeIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_FAILED"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -272,6 +275,7 @@ class AwsIncludeIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -377,6 +381,7 @@ class AwsIncludeIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -645,6 +650,7 @@ class AwsIncludeIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/BackupVaultCfnIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/BackupVaultCfnIntegrationTest.java index 83e266b65e..8d601e2066 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/BackupVaultCfnIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/BackupVaultCfnIntegrationTest.java @@ -117,6 +117,7 @@ class BackupVaultCfnIntegrationTest { } private static String describeStacks(String expectedStatus) { + CfnStackWaits.awaitStatus(STACK, expectedStatus, CFN_AUTH); return given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CfnUnchangedResourceUpdateIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CfnUnchangedResourceUpdateIntegrationTest.java index c174cdd793..031c7b2c79 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CfnUnchangedResourceUpdateIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CfnUnchangedResourceUpdateIntegrationTest.java @@ -95,7 +95,7 @@ class CfnUnchangedResourceUpdateIntegrationTest { given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH) .formParam("Action", "DeleteStack").formParam("StackName", stackName) .when().post("/").then().statusCode(200); - CfnStackWaits.awaitStackDeleted(stackName); + CfnStackWaits.awaitStackDeleted(stackName, CFN_AUTH); } /** @@ -114,6 +114,7 @@ class CfnUnchangedResourceUpdateIntegrationTest { .formParam("TemplateBody", stackWith(body, "probe-q-a-" + suffix)) .when().post("/").then().statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH) .formParam("Action", "DescribeStacks").formParam("StackName", stackName) .when().post("/").then().statusCode(200) @@ -127,6 +128,7 @@ class CfnUnchangedResourceUpdateIntegrationTest { .formParam("TemplateBody", stackWith(body, "probe-q-b-" + suffix)) .when().post("/").then().statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE", CFN_AUTH); given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH) .formParam("Action", "DescribeStacks").formParam("StackName", stackName) .when().post("/").then().statusCode(200) @@ -150,6 +152,7 @@ class CfnUnchangedResourceUpdateIntegrationTest { .formParam("TemplateBody", stackWith(createBody.replace("SUFFIX", suffix), "probe-q-a-" + suffix)) .when().post("/").then().statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); String before = namedPhysicalId(stackName); assertNotNull(before, "no PhysicalResourceId for Named after create"); @@ -158,6 +161,7 @@ class CfnUnchangedResourceUpdateIntegrationTest { .formParam("TemplateBody", stackWith(updateBody.replace("SUFFIX", suffix), "probe-q-b-" + suffix)) .when().post("/").then().statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE", CFN_AUTH); given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH) .formParam("Action", "DescribeStacks").formParam("StackName", stackName) .when().post("/").then().statusCode(200) @@ -333,6 +337,7 @@ class CfnUnchangedResourceUpdateIntegrationTest { .formParam("Action", "CreateStack").formParam("StackName", stackName) .formParam("TemplateBody", initialTemplate) .when().post("/").then().statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH) .formParam("Action", "DescribeStacks").formParam("StackName", stackName) .when().post("/").then().statusCode(200).body(containsString("CREATE_COMPLETE")); @@ -349,6 +354,7 @@ class CfnUnchangedResourceUpdateIntegrationTest { .formParam("Action", "UpdateStack").formParam("StackName", stackName) .formParam("TemplateBody", updatedTemplate) .when().post("/").then().statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE", CFN_AUTH); given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH) .formParam("Action", "DescribeStacks").formParam("StackName", stackName) .when().post("/").then().statusCode(200).body(containsString("UPDATE_COMPLETE")); @@ -379,6 +385,7 @@ class CfnUnchangedResourceUpdateIntegrationTest { .formParam("Action", "CreateStack").formParam("StackName", stackName) .formParam("TemplateBody", initialTemplate) .when().post("/").then().statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH) .formParam("Action", "DescribeStacks").formParam("StackName", stackName) .when().post("/").then().statusCode(200).body(containsString("CREATE_COMPLETE")); @@ -447,6 +454,7 @@ class CfnUnchangedResourceUpdateIntegrationTest { .formParam("Action", "CreateStack").formParam("StackName", stackName) .formParam("TemplateBody", initialTemplate) .when().post("/").then().statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH) .formParam("Action", "DescribeStacks").formParam("StackName", stackName) .when().post("/").then().statusCode(200).body(containsString("CREATE_COMPLETE")); @@ -467,6 +475,7 @@ class CfnUnchangedResourceUpdateIntegrationTest { .formParam("Action", "UpdateStack").formParam("StackName", stackName) .formParam("TemplateBody", updatedTemplate) .when().post("/").then().statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE", CFN_AUTH); given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH) .formParam("Action", "DescribeStacks").formParam("StackName", stackName) .when().post("/").then().statusCode(200).body(containsString("UPDATE_COMPLETE")); @@ -599,6 +608,7 @@ class CfnUnchangedResourceUpdateIntegrationTest { .formParam("TemplateBody", initialTemplate) .when().post("/").then().statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH) .formParam("Action", "DescribeStacks").formParam("StackName", stackName) .when().post("/").then().statusCode(200) @@ -609,6 +619,7 @@ class CfnUnchangedResourceUpdateIntegrationTest { .formParam("TemplateBody", updatedTemplate) .when().post("/").then().statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE", CFN_AUTH); given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH) .formParam("Action", "DescribeStacks").formParam("StackName", stackName) .when().post("/").then().statusCode(200) @@ -813,6 +824,7 @@ class CfnUnchangedResourceUpdateIntegrationTest { .formParam("TemplateBody", initialTemplate) .when().post("/").then().statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH) .formParam("Action", "DescribeStacks").formParam("StackName", stackName) .when().post("/").then().statusCode(200) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationAccountOwnershipIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationAccountOwnershipIntegrationTest.java index cc43effa1f..e5b2e0d3ee 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationAccountOwnershipIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationAccountOwnershipIntegrationTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.cloudformation; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; import io.quarkus.test.junit.QuarkusTest; import io.restassured.response.ValidatableResponse; @@ -166,6 +167,7 @@ class CloudFormationAccountOwnershipIntegrationTest { .formParam("StackName", name) .formParam("TemplateBody", template) .when().post("/").then().statusCode(200).extract().body().asString(); + CfnStackWaits.awaitStatus(name, "CREATE_COMPLETE", auth(account, region)); return body.replaceFirst("(?s).*([^<]+).*", "$1"); } @@ -178,6 +180,7 @@ class CloudFormationAccountOwnershipIntegrationTest { .formParam("StackName", name) .formParam("TemplateBody", template) .when().post("/").then().statusCode(200); + CfnStackWaits.awaitStatus(name, "CREATE_COMPLETE", auth(account, region)); } private static ValidatableResponse describeStack( diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationAsgLaunchTemplateIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationAsgLaunchTemplateIntegrationTest.java index 4760449f35..f236769232 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationAsgLaunchTemplateIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationAsgLaunchTemplateIntegrationTest.java @@ -110,6 +110,7 @@ class CloudFormationAsgLaunchTemplateIntegrationTest { } private void assertStackCreated(String stackName) { + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); String body = describeStacks(stackName); assertThat(body, containsString("CREATE_COMPLETE")); assertThat(body, not(containsString("The specified launch template does not exist."))); @@ -328,6 +329,7 @@ class CloudFormationAsgLaunchTemplateIntegrationTest { } """.formatted(suffix, ltName)); + CfnStackWaits.awaitStatus(stackName, "ROLLBACK_COMPLETE"); assertThat(describeStacks(stackName), containsString("ROLLBACK_COMPLETE")); assertThat(CfnStackWaits.failedResourceReason(stackName, CFN_AUTH), containsString("Value of property OnDemandBaseCapacity must be an integer.")); @@ -446,6 +448,7 @@ class CloudFormationAsgLaunchTemplateIntegrationTest { assertEquals("False", asgChange.get("Replacement")); updateStack(stackName, template2); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); String describe = describeStacks(stackName); assertThat(describe, containsString("UPDATE_COMPLETE")); // ASG must have updated to version 2 because Fn::GetAtt on LatestVersionNumber changed @@ -569,6 +572,7 @@ class CloudFormationAsgLaunchTemplateIntegrationTest { assertThat(describeAutoScalingGroup(asgName), containsString("1")); updateStack(stackName, template2); + CfnStackWaits.awaitStatus(stackName, "UPDATE_ROLLBACK_COMPLETE"); String describe = describeStacks(stackName); assertThat(describe, containsString("UPDATE_ROLLBACK_COMPLETE")); // ASG must have rolled back to Version 1 diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationAutoScalingIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationAutoScalingIntegrationTest.java index 4e46aa3299..1f6642e02f 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationAutoScalingIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationAutoScalingIntegrationTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.cloudformation; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.Test; @@ -83,6 +84,7 @@ class CloudFormationAutoScalingIntegrationTest { .statusCode(200); // Stack completes and Fn::GetAtt(Asg, Arn) resolves to the real ASG ARN. + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -159,6 +161,7 @@ class CloudFormationAutoScalingIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); // Redeploy with a changed DesiredCapacity: LaunchConfiguration is unchanged (immutable, so // must reconcile to a no-op) and the ASG's capacity must reconcile in place. given() @@ -172,6 +175,7 @@ class CloudFormationAutoScalingIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationBatchIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationBatchIntegrationTest.java index aa67b474fa..29636bc783 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationBatchIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationBatchIntegrationTest.java @@ -89,6 +89,7 @@ class CloudFormationBatchIntegrationTest { .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -171,6 +172,7 @@ class CloudFormationBatchIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -245,6 +247,7 @@ class CloudFormationBatchIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); // The update changes only updatable properties, so the entities must be mutated, not // replaced: the physical ids the outputs carry have to survive it. given() @@ -257,6 +260,7 @@ class CloudFormationBatchIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -392,6 +396,7 @@ class CloudFormationBatchIntegrationTest { } private static void assertStackStatus(String stackName, String status) { + CfnStackWaits.awaitStatus(stackName, status); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCdkDeployLoopIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCdkDeployLoopIntegrationTest.java index 244e1ec234..542cb39890 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCdkDeployLoopIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCdkDeployLoopIntegrationTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.cloudformation; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.Test; @@ -130,6 +131,7 @@ class CloudFormationCdkDeployLoopIntegrationTest { .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -203,6 +205,7 @@ class CloudFormationCdkDeployLoopIntegrationTest { .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -251,6 +254,7 @@ class CloudFormationCdkDeployLoopIntegrationTest { .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationChangeSetDiffIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationChangeSetDiffIntegrationTest.java index 490445ab6f..1b460ad6cf 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationChangeSetDiffIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationChangeSetDiffIntegrationTest.java @@ -1,6 +1,7 @@ package io.github.hectorvent.floci.services.cloudformation; import io.github.hectorvent.floci.core.common.XmlParser; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.AfterEach; @@ -81,6 +82,7 @@ class CloudFormationChangeSetDiffIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); // Same template, only the parameter value changes. given() .contentType("application/x-www-form-urlencoded") @@ -142,6 +144,7 @@ class CloudFormationChangeSetDiffIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); // Same template, and the parameter says UsePreviousValue instead of resubmitting its value. given() .contentType("application/x-www-form-urlencoded") @@ -202,6 +205,7 @@ class CloudFormationChangeSetDiffIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); // Same template, but the update omits Suffix entirely - real CloudFormation falls back to // the template Default ("fallback"), which differs from the deployed value ("override"). given() @@ -262,6 +266,7 @@ class CloudFormationChangeSetDiffIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); // Same template, but the update omits Suffix entirely and the template has no Default. An // update does not carry the deployed value over, so CloudFormation refuses the change set // rather than preview, or apply, the parameter without a value. @@ -330,6 +335,7 @@ class CloudFormationChangeSetDiffIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); // The update points QueueSuffix at an SSM parameter that was never put. ExecuteChangeSet // would fail resolving it, but DescribeChangeSet is only a preview - it must not 400 just // because the current value can't be resolved. @@ -388,6 +394,7 @@ class CloudFormationChangeSetDiffIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); // Byte-identical re-submission of the same SAM source: the deployed template is the // *expanded* form, so diffing the raw SAM source against it must not report the // SAM-generated IAM role as removed or the function as modified. @@ -454,6 +461,7 @@ class CloudFormationChangeSetDiffIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "CreateChangeSet") @@ -528,6 +536,7 @@ class CloudFormationChangeSetDiffIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); // The SSM parameter's value changes in Parameter Store; the referencing template parameter // (the SSM parameter *name*) is resubmitted unchanged. Real CloudFormation re-resolves the // SSM value at CreateChangeSet time, so ExecuteChangeSet would apply "two" to the queue — @@ -610,6 +619,7 @@ class CloudFormationChangeSetDiffIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); // Q's definition text is unchanged, but Env flips IsProd from false to true - Q was never // created, and ExecuteChangeSet would create it now. given() @@ -674,6 +684,7 @@ class CloudFormationChangeSetDiffIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); // Q's definition text is unchanged, but Env flips IsProd from true to false - Q was created, // and ExecuteChangeSet would delete it now. given() @@ -820,6 +831,7 @@ class CloudFormationChangeSetDiffIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "CreateChangeSet") diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCloudFrontDistributionIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCloudFrontDistributionIntegrationTest.java index c662598e26..5745a6a859 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCloudFrontDistributionIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCloudFrontDistributionIntegrationTest.java @@ -6,6 +6,7 @@ import io.github.hectorvent.floci.services.cloudfront.model.KeyGroup; import io.github.hectorvent.floci.services.cloudfront.model.OriginAccessControl; import io.github.hectorvent.floci.services.cloudfront.model.PublicKey; import io.github.hectorvent.floci.services.s3.S3Service; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.quarkus.test.junit.QuarkusTest; import jakarta.inject.Inject; import org.junit.jupiter.api.Test; @@ -112,6 +113,7 @@ class CloudFormationCloudFrontDistributionIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); // Stack completes and Fn::GetAtt(Dist, DomainName) resolves to a real *.cloudfront.net domain // (not the unresolved "Dist.DomainName" token). given() @@ -172,6 +174,7 @@ class CloudFormationCloudFrontDistributionIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); Distribution original = distributionsWithAlias(alias).getFirst(); given() @@ -185,6 +188,7 @@ class CloudFormationCloudFrontDistributionIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); List matching = distributionsWithAlias(alias); assertEquals(1, matching.size(), "UpdateStack must not leak a second distribution"); Distribution updated = matching.getFirst(); @@ -257,6 +261,7 @@ class CloudFormationCloudFrontDistributionIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus("cfn-cloudfront-private-" + suffix, "CREATE_COMPLETE"); Distribution distribution = distributionsWithAlias(alias).getFirst(); assertEquals(List.of(defaultKeyGroup.getId()), distribution.getConfig().getDefaultCacheBehavior().getTrustedKeyGroups()); @@ -305,6 +310,7 @@ class CloudFormationCloudFrontDistributionIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "ROLLBACK_COMPLETE"); // On AWS the stack fails because CloudFront rejects the out-of-range value; the // service-level check makes the CloudFormation path share that one copy. given() diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCloudFrontPoliciesIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCloudFrontPoliciesIntegrationTest.java index cf19a45704..c465134c34 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCloudFrontPoliciesIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCloudFrontPoliciesIntegrationTest.java @@ -238,10 +238,12 @@ class CloudFormationCloudFrontPoliciesIntegrationTest { private static void createStack(String stackName, String template) { stackCall("CreateStack", stackName, template); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); } private static void updateStack(String stackName, String template) { stackCall("UpdateStack", stackName, template); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE", CFN_AUTH); } private static void stackCall(String action, String stackName, String template) { diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCloudWatchAlarmIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCloudWatchAlarmIntegrationTest.java index dad33b0698..f329b95375 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCloudWatchAlarmIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCloudWatchAlarmIntegrationTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.cloudformation; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.Test; @@ -60,6 +61,7 @@ class CloudFormationCloudWatchAlarmIntegrationTest { .statusCode(200); // Stack completes and Fn::GetAtt(Alarm, Arn) resolves to the real alarm ARN. + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCloudWatchDashboardIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCloudWatchDashboardIntegrationTest.java index 524673bfa9..a18f0fef2e 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCloudWatchDashboardIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCloudWatchDashboardIntegrationTest.java @@ -380,6 +380,7 @@ class CloudFormationCloudWatchDashboardIntegrationTest { } private static String describeStacks(String stack, String expectedStatus) { + CfnStackWaits.awaitStatus(stack, expectedStatus, CFN_AUTH); return given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCognitoUpdateRollbackIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCognitoUpdateRollbackIntegrationTest.java index d77ecfb2e0..9d06f48cec 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCognitoUpdateRollbackIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCognitoUpdateRollbackIntegrationTest.java @@ -14,6 +14,7 @@ import static io.restassured.RestAssured.given; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * A stack update that changes a Cognito user pool and its client in place and then fails on a later @@ -116,6 +117,8 @@ class CloudFormationCognitoUpdateRollbackIntegrationTest { } private static String describeStacks(String stack, String expectedStatus) { + CfnStackWaits.StackState state = CfnStackWaits.awaitTerminal(stack, CFN_AUTH); + assertEquals(expectedStatus, state.status(), state.reason()); return given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCognitoUserPoolGroupIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCognitoUserPoolGroupIntegrationTest.java index f85ba24fa3..00863732f1 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCognitoUserPoolGroupIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCognitoUserPoolGroupIntegrationTest.java @@ -104,6 +104,7 @@ class CloudFormationCognitoUserPoolGroupIntegrationTest { .then() .statusCode(200); + assertEquals("UPDATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName, CFN_AUTH).status()); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -143,6 +144,7 @@ class CloudFormationCognitoUserPoolGroupIntegrationTest { .then() .statusCode(200); + assertEquals("UPDATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName, CFN_AUTH).status()); cognito("GetGroup", "{\"UserPoolId\": \"" + poolId + "\", \"GroupName\": \"admin\"}") .statusCode(400) .body("__type", equalTo("ResourceNotFoundException")); @@ -159,6 +161,7 @@ class CloudFormationCognitoUserPoolGroupIntegrationTest { String poolId = createStack(stackName, poolAndGroupsTemplate("admin", 0)); updateStack(stackName, poolAndGroupsTemplate("operators", 0)); + assertEquals("UPDATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName, CFN_AUTH).status()); String describeXml = describeStack(stackName); assertThat(describeXml, containsString("UPDATE_COMPLETE")); @@ -182,6 +185,7 @@ class CloudFormationCognitoUserPoolGroupIntegrationTest { String original = output(describeXml, "GroupName"); updateStack(stackName, twoPoolsAndUnnamedGroupTemplate("SecondPool")); + assertEquals("UPDATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName, CFN_AUTH).status()); describeXml = describeStack(stackName); assertThat(describeXml, containsString("UPDATE_COMPLETE")); @@ -332,6 +336,7 @@ class CloudFormationCognitoUserPoolGroupIntegrationTest { .then() .statusCode(200); + assertEquals("CREATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName, CFN_AUTH).status()); String describeXml = given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCreateStackIdentityIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCreateStackIdentityIntegrationTest.java new file mode 100644 index 0000000000..79d22f6965 --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationCreateStackIdentityIntegrationTest.java @@ -0,0 +1,100 @@ +package io.github.hectorvent.floci.services.cloudformation; + +import io.github.hectorvent.floci.services.cloudformation.model.ChangeSet; +import io.github.hectorvent.floci.testing.CfnStackWaits; +import io.quarkus.arc.ClientProxy; +import io.quarkus.test.junit.QuarkusMock; +import io.quarkus.test.junit.QuarkusTest; +import jakarta.inject.Inject; +import org.junit.jupiter.api.Test; +import org.mockito.AdditionalAnswers; +import org.mockito.Mockito; +import org.mockito.stubbing.Answer; + +import java.util.List; +import java.util.UUID; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + +import static io.github.hectorvent.floci.testing.CfnRequests.cfn; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.mockito.Mockito.withSettings; + +@QuarkusTest +class CloudFormationCreateStackIdentityIntegrationTest { + + private static final String TEMPLATE = """ + {"Resources":{"Q":{"Type":"AWS::SQS::Queue","Properties":{}}}} + """; + + @Inject + CloudFormationService service; + + @Test + void createStackDoesNotExecuteAReplacementWithTheSameName() throws Exception { + String stackName = "cfn-create-identity-" + UUID.randomUUID().toString().substring(0, 8); + CloudFormationService original = ClientProxy.unwrap(service); + Answer realService = AdditionalAnswers.delegatesTo(original); + AtomicReference replacement = new AtomicReference<>(); + CloudFormationService replacingService = Mockito.mock(CloudFormationService.class, + withSettings().defaultAnswer(invocation -> { + if (!"createChangeSetForCreateStack".equals(invocation.getMethod().getName())) { + return realService.answer(invocation); + } + ChangeSet initial = (ChangeSet) realService.answer(invocation); + Future deleted = original.deleteStack(initial.getStackId(), List.of(), "us-east-1", + "000000000000"); + deleted.get(5, TimeUnit.SECONDS); + replacement.set(original.createChangeSetForCreateStack(stackName, "initial-create", + TEMPLATE, null, null, List.of(), null, "us-east-1", false)); + assertNotEquals(initial.getStackId(), replacement.get().getStackId()); + return initial; + })); + QuarkusMock.installMockForType(replacingService, CloudFormationService.class); + + try { + cfn("CreateStack", stackName).formParam("TemplateBody", TEMPLATE) + .when().post("/").then().statusCode(400); + assertThat(cfn("DescribeStacks", stackName).when().post("/").asString(), + containsString("" + replacement.get().getStackId() + "")); + assertThat(cfn("DescribeStacks", stackName).when().post("/").asString(), + containsString("REVIEW_IN_PROGRESS")); + } finally { + CfnStackWaits.deleteStack(stackName); + } + } + + @Test + void protectedCreateClearsProtectionWhenItsChangeSetIsDeletedBeforeExecution() { + String stackName = "cfn-create-deleted-cs-" + UUID.randomUUID().toString().substring(0, 8); + CloudFormationService original = ClientProxy.unwrap(service); + Answer realService = AdditionalAnswers.delegatesTo(original); + CloudFormationService deletingService = Mockito.mock(CloudFormationService.class, + withSettings().defaultAnswer(invocation -> { + if (!"createChangeSetForCreateStack".equals(invocation.getMethod().getName())) { + return realService.answer(invocation); + } + ChangeSet initial = (ChangeSet) realService.answer(invocation); + original.deleteChangeSet(initial.getStackId(), initial.getChangeSetId(), "us-east-1"); + return initial; + })); + QuarkusMock.installMockForType(deletingService, CloudFormationService.class); + + try { + cfn("CreateStack", stackName).formParam("TemplateBody", TEMPLATE) + .formParam("EnableTerminationProtection", "true") + .when().post("/").then().statusCode(400) + .body(containsString("ChangeSetNotFoundException")); + String stackXml = cfn("DescribeStacks", stackName).when().post("/") + .then().statusCode(200).extract().asString(); + assertThat(stackXml, containsString("REVIEW_IN_PROGRESS")); + assertThat(stackXml, containsString("false")); + } finally { + original.updateTerminationProtection(stackName, false, "us-east-1"); + CfnStackWaits.deleteStack(stackName); + } + } +} diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationDeleteIdempotencyIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationDeleteIdempotencyIntegrationTest.java index 9c1535e71e..2a61886648 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationDeleteIdempotencyIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationDeleteIdempotencyIntegrationTest.java @@ -65,8 +65,7 @@ class CloudFormationDeleteIdempotencyIntegrationTest { .formParam("TemplateBody", template) .when().post("/").then().statusCode(200); - // CloudFormationQueryHandler awaits executeChangeSet before CreateStack returns, so this - // one-shot assertion verifies the handler's synchronous completion contract. + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); assertStackStatus(stackName, "CREATE_COMPLETE"); // Remove the table out-of-band — mimics a rollback having already deleted it. diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationDescribeStackResourcesFilterIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationDescribeStackResourcesFilterIntegrationTest.java index d2597d7a52..2ddc042be9 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationDescribeStackResourcesFilterIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationDescribeStackResourcesFilterIntegrationTest.java @@ -47,6 +47,7 @@ class CloudFormationDescribeStackResourcesFilterIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); return stackName; } diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationDynamicReferenceIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationDynamicReferenceIntegrationTest.java index 8ce26c2eab..e71c97736e 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationDynamicReferenceIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationDynamicReferenceIntegrationTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.cloudformation; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; import io.quarkus.test.junit.QuarkusTest; import org.hamcrest.Matchers; @@ -77,6 +78,7 @@ class CloudFormationDynamicReferenceIntegrationTest { .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus("cfn-dynref-ssm-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -143,6 +145,7 @@ class CloudFormationDynamicReferenceIntegrationTest { .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus("cfn-dynref-sm-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -203,6 +206,7 @@ class CloudFormationDynamicReferenceIntegrationTest { .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus("cfn-dynref-sns-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -250,6 +254,7 @@ class CloudFormationDynamicReferenceIntegrationTest { .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus("cfn-dynref-ssm-secure-non-rds-stack", "ROLLBACK_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -296,6 +301,7 @@ class CloudFormationDynamicReferenceIntegrationTest { .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus("cfn-dynref-literal-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationDynamoDbGlobalTableIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationDynamoDbGlobalTableIntegrationTest.java index e84d7c62df..2deb6a7b47 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationDynamoDbGlobalTableIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationDynamoDbGlobalTableIntegrationTest.java @@ -124,6 +124,7 @@ class CloudFormationDynamoDbGlobalTableIntegrationTest { } private void assertStackStatus(String stackName, String status) { + CfnStackWaits.awaitStatus(stackName, status, CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationDynamoDbReplicaIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationDynamoDbReplicaIntegrationTest.java index cc7e413f8e..a45cc33955 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationDynamoDbReplicaIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationDynamoDbReplicaIntegrationTest.java @@ -56,6 +56,7 @@ class CloudFormationDynamoDbReplicaIntegrationTest { } private void assertStackStatus(String stackName, String status) { + CfnStackWaits.awaitStatus(stackName, status, CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEc2InstanceIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEc2InstanceIntegrationTest.java index dda19c2953..e28783b203 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEc2InstanceIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEc2InstanceIntegrationTest.java @@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.cloudformation; import io.github.hectorvent.floci.services.ec2.Ec2Service; import io.github.hectorvent.floci.services.ec2.model.Tag; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.quarkus.test.junit.QuarkusTest; import jakarta.inject.Inject; import org.junit.jupiter.api.Test; @@ -64,6 +65,7 @@ class CloudFormationEc2InstanceIntegrationTest { .formParam("TemplateBody", template.formatted(original, original)) .when().post("/").then().statusCode(200); try { + awaitStackStatus(stackName, "CREATE_COMPLETE"); String stack = given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH) .formParam("Action", "DescribeStacks").formParam("StackName", stackName) .when().post("/").then().statusCode(200) @@ -81,6 +83,7 @@ class CloudFormationEc2InstanceIntegrationTest { .formParam("Action", "UpdateStack").formParam("StackName", stackName) .formParam("TemplateBody", template.formatted(desired, desired)) .when().post("/").then().statusCode(200); + awaitStackStatus(stackName, "UPDATE_COMPLETE"); String updated = given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH) .formParam("Action", "DescribeStacks").formParam("StackName", stackName) .when().post("/").then().statusCode(200) @@ -137,6 +140,7 @@ class CloudFormationEc2InstanceIntegrationTest { .then() .statusCode(200); + awaitStackStatus(stackName, "CREATE_COMPLETE"); String describeStacks = given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -458,6 +462,7 @@ class CloudFormationEc2InstanceIntegrationTest { } private static String describeStacks(String stackName, String expectedStatus) { + awaitStackStatus(stackName, expectedStatus); return given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -468,6 +473,11 @@ class CloudFormationEc2InstanceIntegrationTest { .extract().asString(); } + private static void awaitStackStatus(String stackName, String expectedStatus) { + CfnStackWaits.StackState state = CfnStackWaits.awaitTerminal(stackName, CFN_AUTH); + assertEquals(expectedStatus, state.status(), state.reason()); + } + private static String instanceIdFrom(String stackXml) { Matcher m = Pattern.compile("(i-[0-9a-fA-F]+)").matcher(stackXml); assertTrue(m.find(), "expected an instance id in the stack outputs: " + stackXml); diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEc2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEc2IntegrationTest.java index 044c0fc32d..23d9d829f2 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEc2IntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEc2IntegrationTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.cloudformation; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.Test; @@ -81,6 +82,7 @@ class CloudFormationEc2IntegrationTest { .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); // The exported subnet ids must be real subnet-xxxx ids (not the old stub shape). String describeStacks = given() .contentType("application/x-www-form-urlencoded") @@ -174,6 +176,7 @@ class CloudFormationEc2IntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); String describeStacks = given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -242,6 +245,7 @@ class CloudFormationEc2IntegrationTest { .formParam("TemplateBody", template) .when().post("/").then().statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); String describe = given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEc2MetadataOptionsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEc2MetadataOptionsIntegrationTest.java index e029af3024..2565b7797d 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEc2MetadataOptionsIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEc2MetadataOptionsIntegrationTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.cloudformation; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.github.hectorvent.floci.testing.EnforcementFixtures; import io.quarkus.test.junit.QuarkusTest; import io.restassured.path.xml.XmlPath; @@ -529,6 +530,8 @@ class CloudFormationEc2MetadataOptionsIntegrationTest { } private static XmlPath describeStack(String stackName, String expectedStatus) { + CfnStackWaits.awaitStatus(stackName, expectedStatus, + EnforcementFixtures.auth(ACCOUNT, REGION, "cloudformation")); return cfnRequest("DescribeStacks").formParam("StackName", stackName) .post("/").then().statusCode(200) .body(containsString("" + expectedStatus + "")) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEc2NetworkingIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEc2NetworkingIntegrationTest.java index 9b9a0d19e3..0ad63700e5 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEc2NetworkingIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEc2NetworkingIntegrationTest.java @@ -822,6 +822,7 @@ class CloudFormationEc2NetworkingIntegrationTest { } private static String describeStacks(String stack, String expectedStatus) { + CfnStackWaits.awaitStatus(stack, expectedStatus); return cfn("DescribeStacks", stack) .header("Authorization", CFN_AUTH) .when().post("/").then().statusCode(200) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEcsCapacityIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEcsCapacityIntegrationTest.java index 4bdd265040..4ad587d2a5 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEcsCapacityIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEcsCapacityIntegrationTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.cloudformation; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.BeforeAll; @@ -77,6 +78,7 @@ class CloudFormationEcsCapacityIntegrationTest { createStack(stackName, template(clusterName, providerName)); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -91,6 +93,7 @@ class CloudFormationEcsCapacityIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE", CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -190,6 +193,7 @@ class CloudFormationEcsCapacityIntegrationTest { .statusCode(200) .body(containsString("")) .extract().asString(); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); return xml.substring(xml.indexOf("") + "".length(), xml.indexOf("")); } diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEcsServiceStableIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEcsServiceStableIntegrationTest.java index 7f47e4a290..38899307be 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEcsServiceStableIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEcsServiceStableIntegrationTest.java @@ -1,6 +1,7 @@ package io.github.hectorvent.floci.services.cloudformation; import io.github.hectorvent.floci.services.ec2.Ec2Service; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; import io.quarkus.test.junit.QuarkusTest; import io.restassured.response.Response; @@ -161,6 +162,7 @@ class CloudFormationEcsServiceStableIntegrationTest { String name = "cfn-stable-" + Long.toString(System.nanoTime(), 36); stackCall("CreateStack", name, TEMPLATE.formatted(name, "app:v1", 1)); + CfnStackWaits.awaitStatus(name, "CREATE_COMPLETE"); assertThat(stackStatus(name), equalTo("CREATE_COMPLETE")); Response service = describeService(name); @@ -176,8 +178,10 @@ class CloudFormationEcsServiceStableIntegrationTest { void updateStack_ecsService_runsOnlyTheNewRevisionWhenTheUpdateCompletes() { String name = "cfn-stable-upd-" + Long.toString(System.nanoTime(), 36); stackCall("CreateStack", name, TEMPLATE.formatted(name, "app:v1", 1)); + CfnStackWaits.awaitStatus(name, "CREATE_COMPLETE"); stackCall("UpdateStack", name, TEMPLATE.formatted(name, "app:v2", 2)); + CfnStackWaits.awaitStatus(name, "UPDATE_COMPLETE"); assertThat(stackStatus(name), equalTo("UPDATE_COMPLETE")); Response service = describeService(name); @@ -195,9 +199,11 @@ class CloudFormationEcsServiceStableIntegrationTest { String name = "cfn-stable-rb-" + Long.toString(System.nanoTime(), 36); String subnet = Ec2Service.defaultSubnetId("us-east-1", "a"); stackCall("CreateStack", name, AWSVPC_TEMPLATE.formatted(name, 1, subnet)); + CfnStackWaits.awaitStatus(name, "CREATE_COMPLETE"); assertThat(stackStatus(name), equalTo("CREATE_COMPLETE")); stackCall("UpdateStack", name, AWSVPC_TEMPLATE.formatted(name, 2, "subnet-does-not-exist")); + CfnStackWaits.awaitStatus(name, "UPDATE_ROLLBACK_COMPLETE"); assertThat(stackStatus(name), equalTo("UPDATE_ROLLBACK_COMPLETE")); Response service = describeService(name); @@ -226,6 +232,7 @@ class CloudFormationEcsServiceStableIntegrationTest { .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus(name, "CREATE_COMPLETE"); assertThat(stackStatus(name), equalTo("CREATE_COMPLETE")); Response service = describeService(name); assertThat(service.path("services[0].networkConfiguration.awsvpcConfiguration.subnets"), diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEksIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEksIntegrationTest.java index d3809910a2..1b08aeae6e 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEksIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEksIntegrationTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.cloudformation; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.Test; @@ -63,6 +64,7 @@ class CloudFormationEksIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationElbV2ReplacementIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationElbV2ReplacementIntegrationTest.java index ba0edf4235..e13b73f849 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationElbV2ReplacementIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationElbV2ReplacementIntegrationTest.java @@ -49,6 +49,7 @@ class CloudFormationElbV2ReplacementIntegrationTest { String oldTg = output(describeBefore, "TgRef"); updateStack(stackName, template(suffix, "AlbB", "tg-b-" + suffix, "")); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); String describeAfter = describeStack(stackName); assertStatus(describeAfter, "UPDATE_COMPLETE"); String newListener = output(describeAfter, "ListenerRef"); @@ -92,6 +93,7 @@ class CloudFormationElbV2ReplacementIntegrationTest { }""".formatted(suffix); updateStack(stackName, template(suffix, "AlbB", "tg-" + suffix, failingSecret)); + CfnStackWaits.awaitStatus(stackName, "UPDATE_ROLLBACK_COMPLETE"); String describe = describeStack(stackName); assertStatus(describe, "UPDATE_ROLLBACK_COMPLETE"); assertEquals(oldListener, output(describe, "ListenerRef")); @@ -122,12 +124,14 @@ class CloudFormationElbV2ReplacementIntegrationTest { createStack(stackName, fixedResponseTemplate(suffix)); updateStack(stackName, template(suffix, "AlbA", "tg-a-" + suffix, "")); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); String describeBefore = describeStack(stackName); assertStatus(describeBefore, "UPDATE_COMPLETE"); String oldListener = output(describeBefore, "ListenerRef"); String oldTg = output(describeBefore, "TgRef"); updateStack(stackName, template(suffix, "AlbB", "tg-b-" + suffix, "")); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); String describeAfter = describeStack(stackName); assertStatus(describeAfter, "UPDATE_COMPLETE"); assertNotEquals(oldListener, output(describeAfter, "ListenerRef")); @@ -259,6 +263,7 @@ class CloudFormationElbV2ReplacementIntegrationTest { given().formParam("Action", "CreateStack").formParam("Version", "2010-05-15") .formParam("StackName", stackName).formParam("TemplateBody", body) .when().post("/").then().statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); assertStatus(describeStack(stackName), "CREATE_COMPLETE"); } diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEventBusIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEventBusIntegrationTest.java index fea6277138..cc0d337d3a 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEventBusIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEventBusIntegrationTest.java @@ -53,6 +53,7 @@ class CloudFormationEventBusIntegrationTest { } private void assertStackStatus(String stackName, String status) { + CfnStackWaits.awaitStatus(stackName, status, CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationFirehoseIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationFirehoseIntegrationTest.java index 34110df7a0..bebcb367f4 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationFirehoseIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationFirehoseIntegrationTest.java @@ -97,6 +97,7 @@ class CloudFormationFirehoseIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); // Stack completes and Fn::GetAtt(Stream, Arn) resolves to the real delivery stream ARN. given() .contentType("application/x-www-form-urlencoded") diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationGeneratedNameUniquenessIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationGeneratedNameUniquenessIntegrationTest.java index 86d36c40a3..1fc046a0c5 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationGeneratedNameUniquenessIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationGeneratedNameUniquenessIntegrationTest.java @@ -1,6 +1,7 @@ package io.github.hectorvent.floci.services.cloudformation; import io.github.hectorvent.floci.core.common.XmlParser; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.BeforeAll; @@ -97,6 +98,7 @@ class CloudFormationGeneratedNameUniquenessIntegrationTest { createStack(stackName, template); try { + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); String xml = describeStacks(stackName); assertTrue(xml.contains("CREATE_COMPLETE"), "stack should be CREATE_COMPLETE"); diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIamInlinePolicyIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIamInlinePolicyIntegrationTest.java index 07b80f83e8..4d91d0c93e 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIamInlinePolicyIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIamInlinePolicyIntegrationTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.cloudformation; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.Test; @@ -138,6 +139,7 @@ class CloudFormationIamInlinePolicyIntegrationTest { } private static void assertStackStatus(String stackName, String status) { + CfnStackWaits.awaitStatus(stackName, status, CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -310,6 +312,7 @@ class CloudFormationIamInlinePolicyIntegrationTest { createStack(stackName, template); // Managed policy has an ARN (unlike inline), surfaced through Ref. + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -559,6 +562,7 @@ class CloudFormationIamInlinePolicyIntegrationTest { createStack(stackName, template); + CfnStackWaits.awaitStatus(stackName, "ROLLBACK_COMPLETE", CFN_AUTH); String stack = describeStack(stackName, "DescribeStacks"); assertTrue(stack.contains("ROLLBACK_COMPLETE"), "stack should roll back after the inline attachment failure: " + stack); @@ -767,6 +771,7 @@ class CloudFormationIamInlinePolicyIntegrationTest { private static void assertFailedResource(String stackName, String logicalId, String expectedSubject, String expectedReason) { + CfnStackWaits.awaitStatus(stackName, "ROLLBACK_COMPLETE", CFN_AUTH); String stack = describeStack(stackName, "DescribeStacks"); assertTrue( stack.contains("ROLLBACK_COMPLETE"), diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIamRoleInlinePoliciesIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIamRoleInlinePoliciesIntegrationTest.java index 63aa80c7e3..7b61801852 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIamRoleInlinePoliciesIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIamRoleInlinePoliciesIntegrationTest.java @@ -128,6 +128,7 @@ class CloudFormationIamRoleInlinePoliciesIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIamRoleTrustPolicyUpdateIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIamRoleTrustPolicyUpdateIntegrationTest.java index d0bc12142c..47983eb47a 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIamRoleTrustPolicyUpdateIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIamRoleTrustPolicyUpdateIntegrationTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.cloudformation; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.Test; @@ -72,6 +73,7 @@ class CloudFormationIamRoleTrustPolicyUpdateIntegrationTest { } private static void assertStackStatus(String stackName, String status) { + CfnStackWaits.awaitStatus(stackName, status, CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIntegrationTest.java index e29ded3d0f..b2347dca02 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIntegrationTest.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import io.github.hectorvent.floci.services.cloudformation.model.Stack; import io.github.hectorvent.floci.services.ec2.Ec2Service; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.github.hectorvent.floci.testing.MutableClock; import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; import io.quarkus.test.junit.QuarkusTest; @@ -198,6 +199,7 @@ class CloudFormationIntegrationTest { .statusCode(200) .body(containsString("")); + awaitStackStatus("test-stack", "CREATE_COMPLETE"); // 2. Verify S3 Bucket exists given() .header("Host", "cf-test-bucket.localhost") @@ -245,6 +247,7 @@ class CloudFormationIntegrationTest { .when().post("/") .then().statusCode(200).body(containsString("")); + CfnStackWaits.awaitStatus("tp-stack", "CREATE_COMPLETE"); // DescribeStacks reports protection off by default. given() .contentType("application/x-www-form-urlencoded") @@ -290,6 +293,7 @@ class CloudFormationIntegrationTest { .when().post("/") .then().statusCode(200).body(containsString("")); + CfnStackWaits.awaitStatus("tp-del-stack", "CREATE_COMPLETE"); // Enable termination protection. given() .contentType("application/x-www-form-urlencoded") @@ -338,6 +342,7 @@ class CloudFormationIntegrationTest { .when().post("/") .then().statusCode(200).body(containsString("")); + CfnStackWaits.awaitStatus("tp-create-stack", "CREATE_COMPLETE"); // The CreateStackInput flag is honored — DescribeStacks reports protection on. given() .contentType("application/x-www-form-urlencoded") @@ -385,6 +390,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200) .body(containsString("")); + awaitStackStatus("cfn-cors-stack", "CREATE_COMPLETE"); // The bucket's ?cors subresource should reflect the CloudFormation CorsConfiguration. given() @@ -436,6 +442,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200) .body(containsString("")); + awaitStackStatus("cfn-cors-blank-stack", "CREATE_COMPLETE"); // A blank list entry must be skipped rather than emitted as an empty (invalid) element. given() @@ -513,6 +520,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackStatus(stackName, "CREATE_COMPLETE"); given() .when() @@ -531,6 +539,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackStatus(stackName, "UPDATE_COMPLETE"); given() .when() @@ -550,6 +559,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackStatus(stackName, "UPDATE_COMPLETE"); given() .when() @@ -587,6 +597,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200) .body(containsString("")); + awaitStackStatus("cfn-versioning-stack", "CREATE_COMPLETE"); // The bucket's ?versioning subresource should reflect the CloudFormation VersioningConfiguration. given() @@ -621,6 +632,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackStatus("cfn-versioning-unset-stack", "CREATE_COMPLETE"); // No VersioningConfiguration in the template → versioning must stay unset (no element), // matching real AWS behavior for a bucket that was never versioned. @@ -676,6 +688,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackStatus(stackName, "CREATE_COMPLETE"); given() .when() @@ -694,6 +707,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackStatus(stackName, "UPDATE_COMPLETE"); given() .when() @@ -754,6 +768,7 @@ class CloudFormationIntegrationTest { .statusCode(200) .body(containsString("")); + awaitStackStatus("cfn-s3code-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -802,6 +817,7 @@ class CloudFormationIntegrationTest { .statusCode(200) .body(containsString("")); + awaitStackStatus("cfn-nocode-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -849,6 +865,7 @@ class CloudFormationIntegrationTest { .statusCode(200) .body(containsString("")); + awaitStackStatus(stackName, "CREATE_COMPLETE"); String createdResourceXml = given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStackResources") @@ -881,6 +898,7 @@ class CloudFormationIntegrationTest { .statusCode(200) .body(containsString("")); + awaitStackStatus(stackName, "UPDATE_COMPLETE"); String updatedResourceXml = given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStackResources") @@ -939,6 +957,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200) .body(containsString("")); + awaitStackStatus(stackName, "CREATE_COMPLETE"); String createdResourceXml = given() .contentType("application/x-www-form-urlencoded") @@ -963,6 +982,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200) .body(containsString("")); + awaitStackStatus(stackName, "UPDATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -1055,6 +1075,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus(stackName, "CREATE_COMPLETE"); String createdResourceXml = given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStackResources") @@ -1077,6 +1098,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus(stackName, "UPDATE_COMPLETE"); String updatedResourceXml = given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStackResources") @@ -1132,6 +1154,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus(stackName, "CREATE_COMPLETE"); given() .when() .get("/2017-03-31/tags/" + functionArn) @@ -1175,6 +1198,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus(stackName, "UPDATE_COMPLETE"); given() .when() .get("/2017-03-31/tags/" + functionArn) @@ -1230,6 +1254,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "UpdateStack") @@ -1288,6 +1313,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "UpdateStack") @@ -1342,6 +1368,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); ssmParameterTags(parameterName) .body("TagList.size()", equalTo(2)) @@ -1370,6 +1397,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); } private static ValidatableResponse ssmParameterTags(String parameterName) { @@ -1403,6 +1431,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "UpdateStack") @@ -1413,6 +1442,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus(stackName, "UPDATE_COMPLETE"); String updatedResourceXml = given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStackResources") @@ -1474,6 +1504,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus(stackName, "CREATE_COMPLETE"); given() .when() .get("/2015-03-31/functions/" + functionName) @@ -1492,6 +1523,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus(stackName, "UPDATE_COMPLETE"); String resourceXml = given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStackResources") @@ -1550,6 +1582,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackStatus(stackName, "ROLLBACK_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -1624,6 +1657,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200) .body(containsString("")); + awaitStackStatus("cfn-kms-override-stack", "CREATE_COMPLETE"); given() .contentType("application/x-amz-json-1.1") @@ -1682,6 +1716,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackStatus("cfn-http-api-override-stack", "CREATE_COMPLETE"); // Infrastructure tools resend the full tag set, override included, on every update. given() @@ -1693,6 +1728,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackStatus("cfn-http-api-override-stack", "UPDATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -1723,6 +1759,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackStatus("cfn-http-api-override-stack", "UPDATE_ROLLBACK_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -1778,6 +1815,7 @@ class CloudFormationIntegrationTest { .statusCode(200) .body(containsString("")); + awaitStackStatus("cfn-env-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -1828,6 +1866,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200) .body(containsString("")); + awaitStackStatus("cfn-image-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -1874,6 +1913,7 @@ class CloudFormationIntegrationTest { .statusCode(200) .body(containsString("")); + awaitStackStatus("cfn-zipfile-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -1924,6 +1964,7 @@ class CloudFormationIntegrationTest { .statusCode(200) .body(containsString("")); + awaitStackStatus("cfn-inline-zipfile-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -1997,6 +2038,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus("test-dynamo-index-stack", "CREATE_COMPLETE"); // 2. Verify GSI and LSI via DescribeTable given() @@ -2120,6 +2162,7 @@ class CloudFormationIntegrationTest { .body(containsString("")) .extract().asString(); + CfnStackWaits.awaitStatus("arn-events-stack", "CREATE_COMPLETE"); // Extract the ARN from the response String stackArn = createResponse.substring( createResponse.indexOf("") + "".length(), @@ -2216,6 +2259,7 @@ class CloudFormationIntegrationTest { .statusCode(200) .body(containsString("")) .extract().asString(); + CfnStackWaits.awaitStatus("deleted-arn-events-stack", "CREATE_COMPLETE"); String stackArn = createResponse.substring( createResponse.indexOf("") + "".length(), @@ -2302,6 +2346,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus("cfn-nonempty-delete-stack", "CREATE_COMPLETE"); // The managed bucket exists. given() @@ -2541,6 +2586,7 @@ class CloudFormationIntegrationTest { .statusCode(200) .body(containsString("")) .extract().asString(); + CfnStackWaits.awaitStatus("deleted-arn-expiry-stack", "CREATE_COMPLETE"); String stackArn = createResponse.substring( createResponse.indexOf("") + "".length(), @@ -2639,6 +2685,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus("live-no-deletion-time-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -2713,6 +2760,7 @@ class CloudFormationIntegrationTest { .statusCode(200) .body(containsString("")) .extract().asString(); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); String stackArn = createResponse.substring( createResponse.indexOf("") + "".length(), @@ -2862,6 +2910,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus("auto-name-stack", "CREATE_COMPLETE"); // 2. Verify stack completed and the auto-generated table name follows the pattern String describeResponse = given() @@ -2940,6 +2989,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -2951,6 +3001,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -3023,6 +3074,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus("explicit-names-stack", "CREATE_COMPLETE"); // Verify explicit names are used as-is in DescribeStackResources given() @@ -3066,6 +3118,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("S3LowerCase-Stack", "CREATE_COMPLETE"); // The auto-generated name should be all lowercase: s3lowercase-stack-myuppercasebucket-... given() @@ -3105,6 +3158,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("CaseSensitive-Stack", "CREATE_COMPLETE"); // The SQS auto-generated name should preserve case: CaseSensitive-Stack-MyMixedCaseQueue-... given() @@ -3156,6 +3210,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("SchedulerGroupStack", "CREATE_COMPLETE"); given() .when() @@ -3218,6 +3273,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("multi-table-stack", "CREATE_COMPLETE"); // Both tables should have distinct names derived from their logical IDs given() @@ -3259,6 +3315,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("ssm-auto-stack", "CREATE_COMPLETE"); // SSM Parameter physical ID should follow {stackName}-{logicalId}-{suffix} pattern given() @@ -3345,6 +3402,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("getatt-stack", "CREATE_COMPLETE"); // Verify Outputs contain the auto-generated name and ARN given() @@ -3406,6 +3464,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus("sns-auto-stack", "CREATE_COMPLETE"); // SNS Ref returns ARN (which contains the auto-generated topic name) given() .contentType("application/x-www-form-urlencoded") @@ -3445,6 +3504,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus("ECR-Upper-Stack", "CREATE_COMPLETE"); // ECR auto-name should be lowercase given() .contentType("application/x-www-form-urlencoded") @@ -3487,6 +3547,7 @@ class CloudFormationIntegrationTest { .statusCode(200) .body(containsString("")); + awaitStackStatus("gen-secret-default", "CREATE_COMPLETE"); // Verify secret was created and has a generated value (default 32 chars) String body = given() .header("X-Amz-Target", "secretsmanager.GetSecretValue") @@ -3536,6 +3597,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("gen-secret-len64", "CREATE_COMPLETE"); String body = given() .header("X-Amz-Target", "secretsmanager.GetSecretValue") @@ -3588,6 +3650,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("gen-secret-tpl", "CREATE_COMPLETE"); String body = given() .header("X-Amz-Target", "secretsmanager.GetSecretValue") @@ -3639,6 +3702,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("desc-secret-stack", "CREATE_COMPLETE"); // Verify description via DescribeSecret given() @@ -3682,6 +3746,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("desc-gen-stack", "CREATE_COMPLETE"); // Verify description given() @@ -3744,6 +3809,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("both-secret-stack", "ROLLBACK_COMPLETE"); // The resource should have failed provisioning given() @@ -3781,6 +3847,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("no-value-secret-stack", "CREATE_COMPLETE"); given() .header("X-Amz-Target", "secretsmanager.GetSecretValue") @@ -3822,6 +3889,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("auto-gen-stack", "CREATE_COMPLETE"); // Verify resource was created with auto-generated name given() @@ -3866,6 +3934,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("ref-secret-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -3925,6 +3994,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus("cfn-eventbridge-stack", "CREATE_COMPLETE"); // 2. Verify stack is CREATE_COMPLETE given() @@ -4008,6 +4078,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus("cfn-eb-getatt-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -4058,6 +4129,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus("cfn-eb-autoname-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -4129,6 +4201,7 @@ class CloudFormationIntegrationTest { .statusCode(200) .body(containsString("")); + awaitStackStatus("cfn-eb-fifo-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -4200,6 +4273,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("cfn-eb-fifo-e2e-stack", "CREATE_COMPLETE"); // Match the issue #787 reproducer: re-apply ContentBasedDeduplication via // SetQueueAttributes to control for a separate Floci CFN→SQS bug where @@ -4298,6 +4372,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("cfn-eb-no-sqs-params-stack", "CREATE_COMPLETE"); given() .contentType("application/x-amz-json-1.1") @@ -4356,6 +4431,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("cfn-eb-empty-sqs-params-stack", "CREATE_COMPLETE"); given() .contentType("application/x-amz-json-1.1") @@ -4425,6 +4501,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("cfn-eb-mixed-stack", "CREATE_COMPLETE"); given() .contentType("application/x-amz-json-1.1") @@ -4471,6 +4548,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus("dep-order-ref-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -4534,6 +4612,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus("dep-order-getatt-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -4591,6 +4670,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus("dep-order-sub-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -4643,6 +4723,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("cfn-eb-delete-stack", "CREATE_COMPLETE"); // Verify rule exists given() @@ -4664,6 +4745,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackDeleted("cfn-eb-delete-stack"); // Verify rule is gone given() @@ -4793,6 +4875,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus("cfn-pipe-stack", "CREATE_COMPLETE"); // 2. Stack should reach CREATE_COMPLETE given() @@ -4828,6 +4911,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackDeleted("cfn-pipe-stack"); given() .contentType("application/json") @@ -4852,6 +4936,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus("cfn-pipe-update-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "UpdateStack") @@ -4862,6 +4947,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus("cfn-pipe-update-stack", "UPDATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -4894,6 +4980,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackDeleted("cfn-pipe-update-stack"); given() .contentType("application/json") @@ -4967,6 +5054,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -4978,6 +5066,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_ROLLBACK_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -5005,6 +5094,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackDeleted(stackName); given() .contentType("application/json") @@ -5080,6 +5170,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus("cfn-template-url-stack", "CREATE_COMPLETE"); // Verify stack and its resource were provisioned from the S3 template given() @@ -5140,6 +5231,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus("cfn-vhost-template-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -5201,6 +5293,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -5275,6 +5368,7 @@ class CloudFormationIntegrationTest { .statusCode(200) .body(containsString("")); + awaitStackStatus(stackName, "CREATE_COMPLETE"); // 2. Stack must reach CREATE_COMPLETE given() .contentType("application/x-www-form-urlencoded") @@ -5398,6 +5492,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -5489,6 +5584,7 @@ class CloudFormationIntegrationTest { .statusCode(200) .body(containsString("")); + awaitStackStatus(stackName, "CREATE_COMPLETE"); // 2. Stack must reach CREATE_COMPLETE String describeXml = given() .contentType("application/x-www-form-urlencoded") @@ -5551,22 +5647,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); - - long deadline = System.currentTimeMillis() + 10_000; - while (System.currentTimeMillis() < deadline) { - String deleteStatus = given() - .contentType("application/x-www-form-urlencoded") - .formParam("Action", "DescribeStacks") - .formParam("StackName", stackName) - .when() - .post("/") - .then() - .extract().body().asString(); - if (deleteStatus.contains("DELETE_COMPLETE") || deleteStatus.contains("does not exist")) { - break; - } - Thread.sleep(200); - } + awaitStackDeleted(stackName); given() .when() @@ -5628,6 +5709,7 @@ class CloudFormationIntegrationTest { .statusCode(200) .body(containsString("")); + awaitStackStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -5712,6 +5794,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus(stackName, "ROLLBACK_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStackResources") @@ -5758,6 +5841,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus("exporter-stack", "CREATE_COMPLETE"); // Verify Stack A is complete and has export in output given() @@ -5819,6 +5903,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus("importer-stack", "CREATE_COMPLETE"); // Verify Stack B is complete and resolved the import correctly given() @@ -5884,6 +5969,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("sub-exporter-stack", "CREATE_COMPLETE"); // Verify the dynamic export name resolved correctly given() @@ -5924,6 +6010,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("sub-importer-stack", "CREATE_COMPLETE"); // Verify the queue was created with the correctly resolved imported value given() @@ -5969,6 +6056,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("export-rename-stack", "CREATE_COMPLETE"); String newTemplate = """ { @@ -5990,6 +6078,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("export-rename-stack", "UPDATE_COMPLETE"); String exportsXml = given() .contentType("application/x-www-form-urlencoded") @@ -6027,6 +6116,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("duplicate-export-stack-a", "CREATE_COMPLETE"); String secondTemplate = """ { @@ -6048,6 +6138,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("duplicate-export-stack-b", "CREATE_FAILED"); given() .contentType("application/x-www-form-urlencoded") @@ -6098,6 +6189,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("missing-import-stack", "ROLLBACK_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -6169,6 +6261,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -6248,6 +6341,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -6325,6 +6419,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -6417,6 +6512,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); String resourcesXml = given() .contentType("application/x-www-form-urlencoded") @@ -6480,6 +6576,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); String resourcesXml = given() .contentType("application/x-www-form-urlencoded") @@ -6551,6 +6648,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); String resourcesXml = given() .contentType("application/x-www-form-urlencoded") @@ -6658,6 +6756,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus(stackName, "CREATE_COMPLETE"); String resourcesXml = given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStackResources") @@ -6727,6 +6826,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus("cfn-inline-subs-stack", "CREATE_COMPLETE"); String subscriptions = given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "ListSubscriptionsByTopic") @@ -6785,6 +6885,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("cfn-conditional-subs-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -6816,6 +6917,7 @@ class CloudFormationIntegrationTest { .formParam("StackName", "cfn-update-inline-subs-stack") .formParam("TemplateBody", initialTemplate) .when().post("/").then().statusCode(200); + CfnStackWaits.awaitStatus("cfn-update-inline-subs-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -6831,6 +6933,7 @@ class CloudFormationIntegrationTest { .formParam("StackName", "cfn-update-inline-subs-stack") .formParam("TemplateBody", updatedTemplate) .when().post("/").then().statusCode(200); + CfnStackWaits.awaitStatus("cfn-update-inline-subs-stack", "UPDATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -6870,6 +6973,7 @@ class CloudFormationIntegrationTest { .formParam("TemplateBody", template) .when().post("/").then().statusCode(200); + awaitStackStatus("cfn-lambda-inline-subs-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -6934,6 +7038,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); // 1. Verify SNS Topic attributes given() @@ -7039,6 +7144,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); String resourcesXml = given() .contentType("application/x-www-form-urlencoded") @@ -7128,6 +7234,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); String resourcesXml = given() .contentType("application/x-www-form-urlencoded") @@ -7206,6 +7313,7 @@ class CloudFormationIntegrationTest { .statusCode(200) .body(containsString("")); + awaitStackStatus(stackName, "CREATE_COMPLETE"); // 2. Describe Stacks and capture outputs String describeXml = given() .contentType("application/x-www-form-urlencoded") @@ -7331,6 +7439,7 @@ class CloudFormationIntegrationTest { .statusCode(200) .body(containsString("")); + awaitStackStatus(stackName, "CREATE_COMPLETE"); // 2. Describe Stacks and capture outputs String describeXml = given() .contentType("application/x-www-form-urlencoded") @@ -7373,6 +7482,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackDeleted(stackName); // 5. Verify resources are deleted given() @@ -7438,6 +7548,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus("parent-nested-stack", "CREATE_COMPLETE"); // Parent stack reaches CREATE_COMPLETE given() @@ -7608,6 +7719,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus("ws-api-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -7734,6 +7846,7 @@ class CloudFormationIntegrationTest { .statusCode(200) .body(containsString("")); + awaitStackStatus(stackName, "CREATE_COMPLETE"); String describeXml = given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -7842,6 +7955,7 @@ class CloudFormationIntegrationTest { .statusCode(200) .body(containsString("")); + awaitStackStatus(stackName, "CREATE_COMPLETE"); String describeXml = given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -7915,6 +8029,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus(stackName, "CREATE_COMPLETE"); String createXml = given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -7938,6 +8053,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus(stackName, "UPDATE_COMPLETE"); String updateXml = given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -7990,6 +8106,7 @@ class CloudFormationIntegrationTest { .formParam("TemplateBody", template) .when().post("/") .then().statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .formParam("Action", "DescribeSecurityGroups") @@ -8022,6 +8139,7 @@ class CloudFormationIntegrationTest { .formParam("TemplateBody", template) .when().post("/") .then().statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); // Tear the recreated stack back down so the security group is not left behind in the // shared in-memory EC2 store, where it would pollute other tests' DescribeSecurityGroups. @@ -8031,6 +8149,7 @@ class CloudFormationIntegrationTest { .formParam("StackName", stackName) .when().post("/") .then().statusCode(200); + awaitStackDeleted(stackName); } @Test @@ -8075,6 +8194,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); // Sanity: cluster exists before delete given() @@ -8211,6 +8331,7 @@ class CloudFormationIntegrationTest { .statusCode(200) .body(containsString("")); + awaitStackStatus(stackName, "CREATE_COMPLETE"); String describeXml = given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -8341,6 +8462,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); String createXml = given() .contentType("application/x-www-form-urlencoded") @@ -8373,6 +8495,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); given() .formParam("Action", "DescribeListeners") @@ -8432,6 +8555,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); // Sanity: target group exists before delete given() @@ -8559,6 +8683,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); String createXml = apigwv2DescribeStacks(stackName); String apiId = apigwOutputValue(createXml, "ApiId"); @@ -8584,6 +8709,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); String updateXml = apigwv2DescribeStacks(stackName); // Physical IDs are stable across the update (in-place patch, not replacement) @@ -8624,6 +8750,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); apigwv2DescribeStacks(stackName); getRoutes(apiId).body("Items.size()", equalTo(1)) @@ -8740,6 +8867,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); String createXml = apigwv2DescribeStacks(stackName); String apiId = apigwOutputValue(createXml, "ApiId"); @@ -8817,6 +8945,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); String createXml = apigwv2DescribeStacks(stackName); String apiId = apigwOutputValue(createXml, "ApiId"); @@ -8836,6 +8965,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); apigwv2DescribeStacks(stackName); getRoutes(apiId).body("Items.size()", equalTo(1)) @@ -8887,6 +9017,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); String apiId = apigwOutputValue(apigwv2DescribeStacks(stackName), "ApiId"); @@ -8930,6 +9061,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "ROLLBACK_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -9008,6 +9140,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus(stackName, "CREATE_COMPLETE"); String createXml = apigwv2DescribeStacks(stackName); String apiId = apigwOutputValue(createXml, "ApiId"); String authorizerId = apigwOutputValue(createXml, "AuthorizerId"); @@ -9067,6 +9200,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); getAuthorizers(apiId).body("Items.size()", equalTo(1)); @@ -9078,6 +9212,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackDeleted(stackName); // The API was never part of the stack, so it (and GetAuthorizers against it) still works // — the authorizer itself must be gone. @@ -9120,6 +9255,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus(stackName, "CREATE_COMPLETE"); String resourcesXml = given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStackResources") @@ -9178,6 +9314,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); String resourcesXml = given() .contentType("application/x-www-form-urlencoded") @@ -9264,6 +9401,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus(stackName, "CREATE_COMPLETE"); String createXml = apigwv2DescribeStacks(stackName); String apiId = apigwOutputValue(createXml, "ApiId"); @@ -9370,6 +9508,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus(stackName, "CREATE_COMPLETE"); String createXml = apigwv2DescribeStacks(stackName); String apiId = apigwOutputValue(createXml, "ApiId"); @@ -9443,6 +9582,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_FAILED"); given() .contentType("application/x-www-form-urlencoded") @@ -9516,6 +9656,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_FAILED"); given() .contentType("application/x-www-form-urlencoded") @@ -9595,6 +9736,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus(stackName, "CREATE_COMPLETE"); String createXml = apigwv2DescribeStacks(stackName); String apiId = apigwOutputValue(createXml, "ApiId"); @@ -9681,6 +9823,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus(stackName, "CREATE_COMPLETE"); String apiId = apigwOutputValue(apigwv2DescribeStacks(stackName), "ApiId"); getRoutes(apiId).body("Items.size()", equalTo(2)) @@ -9741,6 +9884,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("sfn-cfn-stack", "CREATE_COMPLETE"); String expectedArn = "arn:aws:states:us-east-1:000000000000:stateMachine:cfn-sfn-pipeline"; @@ -9779,6 +9923,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackDeleted("sfn-cfn-stack"); given() .header("X-Amz-Target", "AWSStepFunctions.DescribeStateMachine") @@ -9829,6 +9974,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus(stackName, "CREATE_COMPLETE"); // Update the definition; the StateMachineName is unchanged, so this is an in-place update. given() .contentType("application/x-www-form-urlencoded") @@ -9840,6 +9986,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus(stackName, "UPDATE_COMPLETE"); // The stack update succeeded (no UPDATE_ROLLBACK), and the ARN is stable across the update. String describeXml = given() .contentType("application/x-www-form-urlencoded") @@ -9873,6 +10020,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackDeleted(stackName); } @Test @@ -9919,6 +10067,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -9929,6 +10078,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); given() .header("X-Amz-Target", "AWSStepFunctions.ListTagsForResource") @@ -9953,6 +10103,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); given() .header("X-Amz-Target", "AWSStepFunctions.ListTagsForResource") @@ -9972,6 +10123,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackDeleted(stackName); } @Test @@ -10007,6 +10159,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); String initialRevision = given() .header("X-Amz-Target", "AWSStepFunctions.DescribeStateMachine") @@ -10028,6 +10181,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); given() .header("X-Amz-Target", "AWSStepFunctions.DescribeStateMachine") @@ -10059,6 +10213,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackDeleted(stackName); } @Test @@ -10130,6 +10285,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); String initialRevision = given() .header("X-Amz-Target", "AWSStepFunctions.DescribeStateMachine") @@ -10150,6 +10306,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_ROLLBACK_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -10215,6 +10372,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackDeleted(stackName); } @Test @@ -10263,6 +10421,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -10273,6 +10432,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_ROLLBACK_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -10325,6 +10485,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackDeleted(stackName); } @Test @@ -10383,6 +10544,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "UpdateStack") @@ -10393,6 +10555,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200); + awaitStackStatus(stackName, "UPDATE_ROLLBACK_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -10431,6 +10594,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackDeleted(stackName); } @Test @@ -10467,6 +10631,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .header("X-Amz-Target", "AWSStepFunctions.CreateStateMachine") @@ -10492,6 +10657,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_ROLLBACK_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -10531,6 +10697,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackDeleted(stackName); given() .header("X-Amz-Target", "AWSStepFunctions.DeleteStateMachine") .contentType(SFN_CONTENT_TYPE) @@ -10573,6 +10740,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -10583,6 +10751,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); given() .header("X-Amz-Target", "AWSStepFunctions.DescribeStateMachine") @@ -10627,6 +10796,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackDeleted(stackName); } @Test @@ -10678,6 +10848,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "UpdateStack") @@ -10687,6 +10858,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); given() .header("X-Amz-Target", "AWSStepFunctions.DescribeStateMachine") @@ -10715,6 +10887,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackDeleted(stackName); given() .header("X-Amz-Target", "AWSStepFunctions.DeleteStateMachine") .contentType(SFN_CONTENT_TYPE) @@ -10806,6 +10979,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "UpdateStack") @@ -10815,6 +10989,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); given() .header("X-Amz-Target", "AWSStepFunctions.DescribeStateMachine") @@ -10901,6 +11076,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(invalidTemplate.getKey(), "ROLLBACK_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -10934,6 +11110,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackDeleted(stack); } } @@ -10964,6 +11141,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); String oldArn = physicalIdByLogicalId(given() .contentType("application/x-www-form-urlencoded") @@ -10987,6 +11165,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); String newArn = physicalIdByLogicalId(given() .contentType("application/x-www-form-urlencoded") @@ -11007,6 +11186,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackDeleted(stackName); } @Test @@ -11037,6 +11217,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); String oldArn = physicalIdByLogicalId(given() .contentType("application/x-www-form-urlencoded") @@ -11057,6 +11238,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); String newArn = physicalIdByLogicalId(given() .contentType("application/x-www-form-urlencoded") @@ -11097,6 +11279,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackDeleted(stackName); } @Test @@ -11128,6 +11311,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); String generatedArn = physicalIdByLogicalId(given() .contentType("application/x-www-form-urlencoded") @@ -11149,6 +11333,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); String explicitArn = physicalIdByLogicalId(given() .contentType("application/x-www-form-urlencoded") @@ -11172,6 +11357,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); String regeneratedArn = physicalIdByLogicalId(given() .contentType("application/x-www-form-urlencoded") @@ -11211,6 +11397,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackDeleted(stackName); } @Test @@ -11280,6 +11467,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); String initialRevision = given() .header("X-Amz-Target", "AWSStepFunctions.DescribeStateMachine") @@ -11312,6 +11500,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); String updatedRevision = given() .header("X-Amz-Target", "AWSStepFunctions.DescribeStateMachine") @@ -11350,6 +11539,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + awaitStackDeleted(stackName); } // ── Issue #924: roll back failed stack creates (criterion #9) ──────────── @@ -11388,6 +11578,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("cfn-rollback-stack", "ROLLBACK_COMPLETE"); // The stack rolled back rather than being left half-built given() @@ -11429,6 +11620,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("cfn-rollback-retry-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -11489,6 +11681,7 @@ class CloudFormationIntegrationTest { .formParam("StackName", "cfn-rb-stack") .formParam("TemplateBody", failingTemplate) .when().post("/").then().statusCode(200); + CfnStackWaits.awaitStatus("cfn-rb-stack", "ROLLBACK_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -11539,6 +11732,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus("cfn-rollback-lone-stack", "ROLLBACK_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -11678,6 +11872,7 @@ class CloudFormationIntegrationTest { .formParam("StackName", stackName) .formParam("TemplateBody", failingTemplate) .when().post("/").then().statusCode(200); + CfnStackWaits.awaitStatus(stackName, "ROLLBACK_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -11727,6 +11922,7 @@ class CloudFormationIntegrationTest { .formParam("StackName", stackName) .formParam("TemplateBody", workingTemplate) .when().post("/").then().statusCode(200).body(containsString("")); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -11984,6 +12180,7 @@ class CloudFormationIntegrationTest { .then() .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); String resourcesXml = given() .contentType("application/x-www-form-urlencoded") @@ -12043,6 +12240,7 @@ class CloudFormationIntegrationTest { .formParam("StackName", "cfn-it-transform-stack") .formParam("TemplateBody", template) .when().post("/").then().statusCode(200).body(containsString("")); + CfnStackWaits.awaitStatus("cfn-it-transform-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -12120,6 +12318,7 @@ class CloudFormationIntegrationTest { .formParam("TemplateBody", template) .when().post("/") .then().statusCode(200).body(containsString("")); + CfnStackWaits.awaitStatus("cfn-eventbus-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -12156,12 +12355,14 @@ class CloudFormationIntegrationTest { .formParam("StackName", "cfn-eventbus-delete-stack") .formParam("TemplateBody", template) .when().post("/").then().statusCode(200); + CfnStackWaits.awaitStatus("cfn-eventbus-delete-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DeleteStack") .formParam("StackName", "cfn-eventbus-delete-stack") .when().post("/").then().statusCode(200); + awaitStackDeleted("cfn-eventbus-delete-stack"); // The bus is gone. given() @@ -12199,6 +12400,7 @@ class CloudFormationIntegrationTest { .formParam("StackName", "cfn-teardown-stack") .formParam("TemplateBody", template) .when().post("/").then().statusCode(200).body(containsString("")); + CfnStackWaits.awaitStatus("cfn-teardown-stack", "CREATE_COMPLETE"); // Sanity: the rule exists on the custom bus before teardown. given() @@ -12263,6 +12465,7 @@ class CloudFormationIntegrationTest { .formParam("StackName", "cfn-e2e-stack") .formParam("TemplateBody", template) .when().post("/").then().statusCode(200).body(containsString("")); + CfnStackWaits.awaitStatus("cfn-e2e-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -12342,6 +12545,7 @@ class CloudFormationIntegrationTest { .formParam("StackName", "cfn-eventbuspolicy-stack") .formParam("TemplateBody", template) .when().post("/").then().statusCode(200).body(containsString("")); + CfnStackWaits.awaitStatus("cfn-eventbuspolicy-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -12405,6 +12609,7 @@ class CloudFormationIntegrationTest { .formParam("StackName", "cfn-stmt-stack") .formParam("TemplateBody", template) .when().post("/").then().statusCode(200).body(containsString("")); + CfnStackWaits.awaitStatus("cfn-stmt-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") @@ -12469,6 +12674,7 @@ class CloudFormationIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationKinesisIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationKinesisIntegrationTest.java index e52f09cda3..a7ac59bd51 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationKinesisIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationKinesisIntegrationTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.cloudformation; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; import io.restassured.config.EncoderConfig; @@ -58,6 +59,7 @@ class CloudFormationKinesisIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); // Stack completes and Fn::GetAtt(Stream, Arn) resolves to the real stream ARN. given() .contentType("application/x-www-form-urlencoded") @@ -108,6 +110,7 @@ class CloudFormationKinesisIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -119,6 +122,7 @@ class CloudFormationKinesisIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE", CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaAddressingIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaAddressingIntegrationTest.java index 5aeb22a198..7854e88f44 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaAddressingIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaAddressingIntegrationTest.java @@ -88,6 +88,7 @@ class CloudFormationLambdaAddressingIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -201,6 +202,7 @@ class CloudFormationLambdaAddressingIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -213,6 +215,7 @@ class CloudFormationLambdaAddressingIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); // "Ver" must still be version 1: the update must not republish an unchanged version. given() .contentType("application/x-www-form-urlencoded") diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaEventInvokeConfigIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaEventInvokeConfigIntegrationTest.java index fc9172c1ff..928ba56d11 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaEventInvokeConfigIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaEventInvokeConfigIntegrationTest.java @@ -270,6 +270,7 @@ class CloudFormationLambdaEventInvokeConfigIntegrationTest { } private static String describeStacks(String stack, String expectedStatus) { + assertEquals(expectedStatus, CfnStackWaits.awaitTerminal(stack, CFN_AUTH).status()); return given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaHotReloadIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaHotReloadIntegrationTest.java index 2c03304474..e713c91a40 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaHotReloadIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaHotReloadIntegrationTest.java @@ -33,6 +33,7 @@ class CloudFormationLambdaHotReloadIntegrationTest { createStack(stackName, template(fnName, hostPath)); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); describeStacks(stackName) .body(containsString("CREATE_COMPLETE")); @@ -62,6 +63,8 @@ class CloudFormationLambdaHotReloadIntegrationTest { createStack(stackName, template(fnName, "relative/dist")); + CfnStackWaits.StackState state = CfnStackWaits.awaitTerminal(stackName, CFN_AUTH); + assertThat(state.status(), not("CREATE_COMPLETE")); describeStacks(stackName) .body(not(containsString("CREATE_COMPLETE"))); assertThat(CfnStackWaits.failedResourceReason(stackName, CFN_AUTH), diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaMicrovmsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaMicrovmsIntegrationTest.java index 66846d3a14..ad4f1cfce8 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaMicrovmsIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaMicrovmsIntegrationTest.java @@ -84,6 +84,7 @@ class CloudFormationLambdaMicrovmsIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -263,6 +264,7 @@ class CloudFormationLambdaMicrovmsIntegrationTest { } private static String describeStacks(String stackName, String expectedStatus) { + CfnStackWaits.awaitStatus(stackName, expectedStatus, CFN_AUTH); return given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaMissingS3CodeIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaMissingS3CodeIntegrationTest.java index c68b464c51..82fb0ecd2a 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaMissingS3CodeIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaMissingS3CodeIntegrationTest.java @@ -1,9 +1,11 @@ package io.github.hectorvent.floci.services.cloudformation; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.Test; import static io.restassured.RestAssured.given; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; @@ -53,6 +55,8 @@ class CloudFormationLambdaMissingS3CodeIntegrationTest { } private static void assertStackFailed(String stackName) { + CfnStackWaits.StackState state = CfnStackWaits.awaitTerminal(stackName, CFN_AUTH); + assertThat(state.status(), not("CREATE_COMPLETE")); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -95,6 +99,7 @@ class CloudFormationLambdaMissingS3CodeIntegrationTest { // handler is correct and present in the real package that was never fetched. createStack(stackName, template(fnName, "src/api.handler")); + assertStackFailed(stackName); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaStubCodeAllowedIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaStubCodeAllowedIntegrationTest.java index 3e33a5ef78..d217f0b3ab 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaStubCodeAllowedIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaStubCodeAllowedIntegrationTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.cloudformation; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.github.hectorvent.floci.testing.CloudFormationSettingsProfile; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.TestProfile; @@ -36,6 +37,7 @@ class CloudFormationLambdaStubCodeAllowedIntegrationTest { createStack(stackName, template(fnName, "index.handler")); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaWebIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaWebIntegrationTest.java index ebce28eb52..dcfd1aee71 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaWebIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaWebIntegrationTest.java @@ -8,6 +8,7 @@ import io.github.hectorvent.floci.services.lambdaweb.LambdaWebCodeBuckets; import io.github.hectorvent.floci.services.lambdaweb.LambdaWebRoles; import io.github.hectorvent.floci.services.lambdaweb.LambdaWebZips; import io.github.hectorvent.floci.services.s3.S3Service; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.quarkus.test.InjectMock; import io.quarkus.test.junit.QuarkusTest; import io.restassured.response.ValidatableResponse; @@ -306,6 +307,7 @@ class CloudFormationLambdaWebIntegrationTest { } private static String describeStacks(String stackName, String expectedStatus) { + assertEquals(expectedStatus, CfnStackWaits.awaitTerminal(stackName, CFN_AUTH).status()); return given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLaunchTemplateIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLaunchTemplateIntegrationTest.java index e299194b61..5d266d082d 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLaunchTemplateIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLaunchTemplateIntegrationTest.java @@ -80,6 +80,7 @@ class CloudFormationLaunchTemplateIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -146,6 +147,7 @@ class CloudFormationLaunchTemplateIntegrationTest { .statusCode(200); // Stack completes, Ref resolves to a launch template id, GetAtt resolves the version. + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationListIntrinsicsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationListIntrinsicsIntegrationTest.java index 06e1351ce0..beb0320695 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationListIntrinsicsIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationListIntrinsicsIntegrationTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.cloudformation; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.BeforeAll; @@ -65,6 +66,7 @@ class CloudFormationListIntrinsicsIntegrationTest { .when().post("/") .then().statusCode(200); + CfnStackWaits.awaitStatus(name, tagged ? "CREATE_COMPLETE" : "UPDATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationListStacksIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationListStacksIntegrationTest.java index c9f030a23c..3f0fdfd791 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationListStacksIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationListStacksIntegrationTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.cloudformation; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.Test; @@ -46,6 +47,8 @@ class CloudFormationListStacksIntegrationTest { } """.formatted(suffix)); + CfnStackWaits.awaitStatus(completeStack, "CREATE_COMPLETE"); + CfnStackWaits.awaitStatus(rolledBackStack, "ROLLBACK_COMPLETE"); String response = given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "ListStacks") diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLogsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLogsIntegrationTest.java index ed1d7ed070..29d3cdf903 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLogsIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLogsIntegrationTest.java @@ -1,6 +1,7 @@ package io.github.hectorvent.floci.services.cloudformation; import io.github.hectorvent.floci.core.common.XmlParser; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; import io.restassured.config.EncoderConfig; @@ -59,6 +60,7 @@ class CloudFormationLogsIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); // Stack completes and Fn::GetAtt(LogGroup, Arn) resolves to the log group ARN. given() .contentType("application/x-www-form-urlencoded") @@ -107,6 +109,7 @@ class CloudFormationLogsIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -118,6 +121,7 @@ class CloudFormationLogsIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE", CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -191,6 +195,7 @@ class CloudFormationLogsIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); String beforeXml = given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -215,6 +220,7 @@ class CloudFormationLogsIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE", CFN_AUTH); String afterXml = given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -252,6 +258,7 @@ class CloudFormationLogsIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -263,6 +270,7 @@ class CloudFormationLogsIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE", CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -322,6 +330,7 @@ class CloudFormationLogsIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -333,6 +342,7 @@ class CloudFormationLogsIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_ROLLBACK_COMPLETE", CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -391,6 +401,7 @@ class CloudFormationLogsIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -402,6 +413,7 @@ class CloudFormationLogsIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE", CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationManagedPolicyUpdateIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationManagedPolicyUpdateIntegrationTest.java index da59b65918..5d5be41620 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationManagedPolicyUpdateIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationManagedPolicyUpdateIntegrationTest.java @@ -5,6 +5,7 @@ import io.github.hectorvent.floci.core.storage.StorageBackend; import io.github.hectorvent.floci.services.cloudformation.model.Stack; import io.github.hectorvent.floci.services.iam.IamService; import io.github.hectorvent.floci.services.iam.model.IamRole; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.quarkus.arc.ClientProxy; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.mockito.InjectSpy; @@ -150,6 +151,7 @@ class CloudFormationManagedPolicyUpdateIntegrationTest { } private static void assertStackStatus(String stackName, String status) { + CfnStackWaits.awaitStatus(stackName, status, CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationNetworkAclIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationNetworkAclIntegrationTest.java index 96d48fdf21..bd0e2c78c8 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationNetworkAclIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationNetworkAclIntegrationTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.cloudformation; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.Test; @@ -70,6 +71,7 @@ class CloudFormationNetworkAclIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); String describe = given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationPersistenceIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationPersistenceIntegrationTest.java index 5c78194d1e..11be14404e 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationPersistenceIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationPersistenceIntegrationTest.java @@ -15,11 +15,13 @@ import org.junit.jupiter.api.extension.RegisterExtension; import java.nio.file.Files; import java.nio.file.Path; +import java.time.Duration; import java.util.Map; import java.util.Optional; import static io.github.hectorvent.floci.testing.PersistentStorageProfile.STORAGE_DIR; import static io.restassured.RestAssured.given; +import static org.awaitility.Awaitility.await; import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -84,6 +86,7 @@ class CloudFormationPersistenceIntegrationTest { given().when().head("/cfn-persist-it-bucket").then().statusCode(404); }); + CfnStackWaits.awaitStatus("persist-it-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -97,7 +100,11 @@ class CloudFormationPersistenceIntegrationTest { // Read the on-disk file the way a fresh Floci process would on the next boot. PersistentStorage store = new PersistentStorage<>( STACKS_FILE, new TypeReference>() {}); - store.load(); + await().atMost(Duration.ofSeconds(10)).untilAsserted(() -> { + store.load(); + assertEquals("CREATE_COMPLETE", store.get("000000000000/us-east-1:persist-it-stack") + .map(Stack::getStatus).orElse(null)); + }); // Account-prefixed key: /: Optional loaded = store.get("000000000000/us-east-1:persist-it-stack"); diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationPipesCleanupIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationPipesCleanupIntegrationTest.java index fb826da99b..4d8e8df84e 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationPipesCleanupIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationPipesCleanupIntegrationTest.java @@ -54,6 +54,7 @@ class CloudFormationPipesCleanupIntegrationTest { updateStack(stackName, template(newName, suffix)); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -105,6 +106,7 @@ class CloudFormationPipesCleanupIntegrationTest { updateStack(stackName, template(newName, suffix)); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -162,6 +164,7 @@ class CloudFormationPipesCleanupIntegrationTest { updateStack(stackName, template(newName, suffix)); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE_CLEANUP_IN_PROGRESS"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -175,6 +178,7 @@ class CloudFormationPipesCleanupIntegrationTest { assertPipe(oldName); assertPipe(newName); + verify(pipesService, Mockito.timeout(5_000)).deletePipe(eq(oldName), anyString()); Mockito.doCallRealMethod().when(pipesService).deletePipe(eq(oldName), anyString()); given() @@ -232,6 +236,8 @@ class CloudFormationPipesCleanupIntegrationTest { updateStack(stackName, template(newName, suffix)); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE_CLEANUP_IN_PROGRESS"); + verify(pipesService, Mockito.timeout(5_000)).deletePipe(eq(oldName), anyString()); Mockito.doCallRealMethod().when(pipesService).deletePipe(eq(oldName), anyString()); given() @@ -286,6 +292,7 @@ class CloudFormationPipesCleanupIntegrationTest { } }""".formatted(suffix))); + CfnStackWaits.awaitStatus(stackName, "UPDATE_ROLLBACK_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -369,6 +376,7 @@ class CloudFormationPipesCleanupIntegrationTest { } }""".formatted(suffix))); + CfnStackWaits.awaitStatus(stackName, "UPDATE_ROLLBACK_FAILED"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -407,6 +415,7 @@ class CloudFormationPipesCleanupIntegrationTest { // "No updates are to be performed.": a new output makes it an update. updateStack(stackName, CfnUpdates.forceUpdate(renameRollbackTemplate(priorName, ""))); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); given() .contentType("application/json") .when() @@ -447,6 +456,7 @@ class CloudFormationPipesCleanupIntegrationTest { updateStack(stackName, tagReconcileTemplate(pipeName, "after", "team", "after")); + CfnStackWaits.awaitStatus(stackName, "UPDATE_ROLLBACK_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -492,6 +502,7 @@ class CloudFormationPipesCleanupIntegrationTest { updateStack(stackName, tagReconcileTemplate(pipeName, "after", "team", "after")); + CfnStackWaits.awaitStatus(stackName, "UPDATE_ROLLBACK_FAILED"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -579,6 +590,7 @@ class CloudFormationPipesCleanupIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); } private static void updateStack(String stackName, String templateBody) { diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationPolicyDocumentIntrinsicsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationPolicyDocumentIntrinsicsIntegrationTest.java index 54a3f81f19..0b5d32b070 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationPolicyDocumentIntrinsicsIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationPolicyDocumentIntrinsicsIntegrationTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.cloudformation; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.quarkus.test.junit.QuarkusTest; import io.restassured.response.Response; import org.junit.jupiter.api.Test; @@ -161,6 +162,7 @@ class CloudFormationPolicyDocumentIntrinsicsIntegrationTest { String policyName = "sub-shorthand-policy-" + suffix; createStack(stackName, stackWithSubShorthandPolicy(roleName, bucketName, policyName)); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); cfnQuery("DescribeStacks", stackName).then().statusCode(200) .body(containsString("CREATE_COMPLETE")); diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationRdsDynamicReferenceIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationRdsDynamicReferenceIntegrationTest.java index 948a937cf0..ae6b64eaef 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationRdsDynamicReferenceIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationRdsDynamicReferenceIntegrationTest.java @@ -137,6 +137,7 @@ class CloudFormationRdsDynamicReferenceIntegrationTest { createStack(stackName, mapper.writeValueAsString(document)); stackCreated = true; + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); String describeXml = describeStack(stackName); assertTrue(describeXml.contains("CREATE_COMPLETE"), "an ssm-secure master password is legal on RDS and must provision: " + describeXml); @@ -167,6 +168,7 @@ class CloudFormationRdsDynamicReferenceIntegrationTest { "{{resolve:ssm:" + parameterName + "}}")); stackCreated = true; + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); String describeXml = describeStack(stackName); assertTrue(describeXml.contains("CREATE_COMPLETE"), "a plain ssm master password must still resolve: " + describeXml); diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationRdsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationRdsIntegrationTest.java index de21c33dd4..2faf7c7749 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationRdsIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationRdsIntegrationTest.java @@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.cloudformation; import io.github.hectorvent.floci.core.common.XmlParser; import io.github.hectorvent.floci.services.ec2.Ec2Service; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.Test; @@ -61,6 +62,7 @@ class CloudFormationRdsIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); // Stack reaches CREATE_COMPLETE and Ref(DbSubnets) exports the subnet group name. given() .contentType("application/x-www-form-urlencoded") @@ -108,6 +110,7 @@ class CloudFormationRdsIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); String beforeXml = given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -134,6 +137,7 @@ class CloudFormationRdsIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE", CFN_AUTH); String afterXml = given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -210,6 +214,7 @@ class CloudFormationRdsIntegrationTest { .statusCode(200); try { + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); String xml = given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceConditionIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceConditionIntegrationTest.java index c52cb4dc18..76714b1a55 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceConditionIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceConditionIntegrationTest.java @@ -1535,6 +1535,7 @@ class CloudFormationResourceConditionIntegrationTest { .then() .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); } private static void updateStack(String stackName, String template) { @@ -1548,6 +1549,7 @@ class CloudFormationResourceConditionIntegrationTest { .then() .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); } private static void deleteStack(String stackName) { diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationRollbackCompleteUpdateIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationRollbackCompleteUpdateIntegrationTest.java index 3618786c7b..149650ff5c 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationRollbackCompleteUpdateIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationRollbackCompleteUpdateIntegrationTest.java @@ -366,6 +366,7 @@ class CloudFormationRollbackCompleteUpdateIntegrationTest { } private static void assertStackStatus(String stackName, String status) { + CfnStackWaits.awaitStatus(stackName, status); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationRoute53RecordSetIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationRoute53RecordSetIntegrationTest.java index 93c7f143c0..4022e8e25f 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationRoute53RecordSetIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationRoute53RecordSetIntegrationTest.java @@ -1098,6 +1098,7 @@ class CloudFormationRoute53RecordSetIntegrationTest { } private void assertStackStatus(String stackName, String status) { + CfnStackWaits.awaitStatus(stackName, status, CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationSecretTargetAttachmentIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationSecretTargetAttachmentIntegrationTest.java index 10c3f1bd8a..3f905ab7fd 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationSecretTargetAttachmentIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationSecretTargetAttachmentIntegrationTest.java @@ -76,6 +76,7 @@ class CloudFormationSecretTargetAttachmentIntegrationTest { createStack(stackName, template); stackCreated = true; + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); String describeXml = describeStack(stackName); assertTrue(describeXml.contains("CREATE_COMPLETE"), "stack should be CREATE_COMPLETE: " + describeXml); @@ -156,6 +157,7 @@ class CloudFormationSecretTargetAttachmentIntegrationTest { createStack(stackName, template); stackCreated = true; + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); String describeXml = describeStack(stackName); assertTrue(describeXml.contains("CREATE_COMPLETE"), "stack should be CREATE_COMPLETE: " + describeXml); @@ -226,6 +228,7 @@ class CloudFormationSecretTargetAttachmentIntegrationTest { createStack(stackName, template); stackCreated = true; + CfnStackWaits.awaitStatus(stackName, "ROLLBACK_COMPLETE", CFN_AUTH); String describeXml = describeStack(stackName); assertTrue(describeXml.contains("ROLLBACK_COMPLETE"), "stack should be ROLLBACK_COMPLETE: " + describeXml); @@ -293,6 +296,7 @@ class CloudFormationSecretTargetAttachmentIntegrationTest { createStack(stackName, template); stackCreated = true; + CfnStackWaits.awaitStatus(stackName, "ROLLBACK_COMPLETE", CFN_AUTH); String describeXml = describeStack(stackName); assertTrue(describeXml.contains("ROLLBACK_COMPLETE"), "stack should be ROLLBACK_COMPLETE: " + describeXml); diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationSecurityGroupRulesIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationSecurityGroupRulesIntegrationTest.java index a97537b2ed..d8a12861b4 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationSecurityGroupRulesIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationSecurityGroupRulesIntegrationTest.java @@ -90,6 +90,7 @@ class CloudFormationSecurityGroupRulesIntegrationTest { .extract().asString(); String stackId = between(created, "", ""); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); String describe = given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -383,6 +384,7 @@ class CloudFormationSecurityGroupRulesIntegrationTest { .formParam("StackName", stackName) .formParam("TemplateBody", template) .when().post("/").then().statusCode(200).extract().asString(); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -402,6 +404,7 @@ class CloudFormationSecurityGroupRulesIntegrationTest { .formParam("StackName", stackName) .formParam("TemplateBody", template) .when().post("/").then().statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE", CFN_AUTH); } private static String output(String stackName, String key) { diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationServiceRestoreIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationServiceRestoreIntegrationTest.java index 7847694feb..b226213e62 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationServiceRestoreIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationServiceRestoreIntegrationTest.java @@ -9,6 +9,7 @@ import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnResour import io.quarkus.arc.ClientProxy; import io.quarkus.test.junit.QuarkusMock; import io.quarkus.test.junit.QuarkusTest; +import io.restassured.response.Response; import jakarta.inject.Inject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -22,12 +23,15 @@ import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.TreeMap; +import java.util.UUID; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import static io.github.hectorvent.floci.testing.CfnRequests.cfn; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.withSettings; @@ -127,6 +131,49 @@ class CloudFormationServiceRestoreIntegrationTest { assertEquals("DELETE_COMPLETE", stack.getStatus()); } + @Test + void rejectedProtectedCreateLeavesDeletablePlaceholder() throws Exception { + String targetStack = uniqueStackName("protected"); + List> runningOperations = fillExecutor(); + try { + Response rejected = cfn("CreateStack", targetStack) + .formParam("TemplateBody", TEMPLATE) + .formParam("EnableTerminationProtection", "true") + .when().post("/"); + assertEquals(400, rejected.statusCode(), rejected.asString()); + assertTrue(rejected.asString().contains("LimitExceededException"), rejected.asString()); + + Stack placeholder = service.describeStacks(targetStack, REGION).getFirst(); + assertEquals("REVIEW_IN_PROGRESS", placeholder.getStatus()); + assertFalse(placeholder.isEnableTerminationProtection()); + } finally { + release(runningOperations); + } + + service.deleteStack(targetStack, REGION, regionResolver.getAccountId()) + .get(TIMEOUT_SECONDS, TimeUnit.SECONDS); + } + + @Test + void rejectedCreateCleanupDoesNotUnprotectAnExecutingStack() throws Exception { + String targetStack = uniqueStackName("executing"); + ChangeSet initial = service.createChangeSetForCreateStack(targetStack, "initial-create", + TEMPLATE, null, Map.of(), List.of(), Map.of(), REGION, true); + Future execution = service.executeChangeSet(targetStack, "initial-create", REGION); + try { + service.clearProtectionAfterRejectedCreate(targetStack, initial, REGION); + Stack stack = service.describeStacks(targetStack, REGION).getFirst(); + assertEquals("CREATE_IN_PROGRESS", stack.getStatus()); + assertTrue(stack.isEnableTerminationProtection()); + } finally { + releaseOperations.countDown(); + execution.get(TIMEOUT_SECONDS, TimeUnit.SECONDS); + service.updateTerminationProtection(targetStack, false, REGION); + service.deleteStack(targetStack, REGION, regionResolver.getAccountId()) + .get(TIMEOUT_SECONDS, TimeUnit.SECONDS); + } + } + /** Starts change set executions that block in provisioning until every thread and queue slot is taken. */ private List> fillExecutor() throws InterruptedException { List fillerStacks = new ArrayList<>(); @@ -189,6 +236,6 @@ class CloudFormationServiceRestoreIntegrationTest { } private static String uniqueStackName(String kind) { - return STACK_PREFIX + kind + "-" + System.nanoTime(); + return STACK_PREFIX + kind + "-" + UUID.randomUUID(); } } diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationSlowStackResponseIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationSlowStackResponseIntegrationTest.java new file mode 100644 index 0000000000..cff1d4bced --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationSlowStackResponseIntegrationTest.java @@ -0,0 +1,176 @@ +package io.github.hectorvent.floci.services.cloudformation; + +import io.github.hectorvent.floci.services.cloudformation.model.StackResource; +import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnResourceDispatcher; +import io.github.hectorvent.floci.testing.CfnStackWaits; +import io.quarkus.arc.ClientProxy; +import io.quarkus.test.junit.QuarkusMock; +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.response.Response; +import io.restassured.specification.RequestSpecification; +import jakarta.inject.Inject; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.AdditionalAnswers; +import org.mockito.Mockito; +import org.mockito.stubbing.Answer; + +import java.util.Arrays; +import java.util.UUID; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; + +import static io.github.hectorvent.floci.testing.CfnRequests.cfn; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.withSettings; + +@QuarkusTest +class CloudFormationSlowStackResponseIntegrationTest { + + private static final String PREFIX = "slow-stack-response-"; + private static final String SLOW_RESOURCE = "AWS::Test::Resource"; + private static final String SLOW_TEMPLATE = """ + {"Resources":{"Slow":{"Type":"AWS::Test::Resource","Properties":{}}}} + """; + + @Inject + CfnResourceDispatcher provisioner; + + private final CountDownLatch provisioningStarted = new CountDownLatch(1); + private final CountDownLatch releaseProvisioning = new CountDownLatch(1); + + @BeforeEach + void blockSlowResource() { + Answer realProvisioner = AdditionalAnswers.delegatesTo(ClientProxy.unwrap(provisioner)); + CfnResourceDispatcher blockingProvisioner = Mockito.mock(CfnResourceDispatcher.class, + withSettings().defaultAnswer(invocation -> { + if (!"provision".equals(invocation.getMethod().getName()) + || !SLOW_RESOURCE.equals(invocation.getArgument(1)) + || Arrays.stream(invocation.getArguments()).noneMatch( + argument -> argument instanceof String name && name.startsWith(PREFIX))) { + return realProvisioner.answer(invocation); + } + provisioningStarted.countDown(); + assertTrue(releaseProvisioning.await(15, TimeUnit.SECONDS), + "blocked provisioning was not released"); + StackResource resource = new StackResource(); + resource.setLogicalId(invocation.getArgument(0)); + resource.setResourceType(SLOW_RESOURCE); + resource.setPhysicalId("slow-resource"); + resource.setStatus("CREATE_COMPLETE"); + return resource; + })); + QuarkusMock.installMockForType(blockingProvisioner, CfnResourceDispatcher.class); + } + + @Test + void createStackReturnsStackIdWhileResourceIsStillProvisioning() throws Exception { + String stackName = uniqueStackName(); + try { + assertRespondsBeforeProvisioningCompletes("CreateStack", stackName, SLOW_TEMPLATE, + "CREATE_IN_PROGRESS"); + assertEquals("CREATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status()); + } finally { + releaseProvisioning.countDown(); + deleteStack(stackName); + } + } + + @Test + void updateStackReturnsStackIdWhileResourceIsStillProvisioning() throws Exception { + String stackName = uniqueStackName(); + String baseTemplate = """ + {"Resources":{"Base":{"Type":"AWS::SQS::Queue","Properties":{"QueueName":"%s"}}}} + """.formatted(stackName); + String updatedTemplate = """ + {"Resources":{"Base":{"Type":"AWS::SQS::Queue","Properties":{"QueueName":"%s"}}, + "Slow":{"Type":"AWS::Test::Resource","Properties":{}}}} + """.formatted(stackName); + try { + String createdStackId = cfn("CreateStack", stackName).formParam("TemplateBody", baseTemplate) + .when().post("/").then().statusCode(200).extract().xmlPath() + .getString("**.find { it.name() == 'StackId' }"); + assertEquals("CREATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status()); + + assertEquals(createdStackId, assertRespondsBeforeProvisioningCompletes("UpdateStack", stackName, + updatedTemplate, "UPDATE_IN_PROGRESS")); + assertEquals("UPDATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status()); + } finally { + releaseProvisioning.countDown(); + deleteStack(stackName); + } + } + + @Test + void protectedCreateStackRejectsDeleteWhileResourceIsStillProvisioning() throws Exception { + String stackName = uniqueStackName(); + try { + assertRespondsBeforeProvisioningCompletes("CreateStack", stackName, SLOW_TEMPLATE, + "CREATE_IN_PROGRESS", true); + assertEquals("CREATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status()); + } finally { + releaseProvisioning.countDown(); + cfn("UpdateTerminationProtection", stackName) + .formParam("EnableTerminationProtection", "false") + .when().post("/").then().statusCode(200); + deleteStack(stackName); + } + } + + private String assertRespondsBeforeProvisioningCompletes(String action, String stackName, + String template, String inProgressStatus) throws Exception { + return assertRespondsBeforeProvisioningCompletes(action, stackName, template, inProgressStatus, false); + } + + private String assertRespondsBeforeProvisioningCompletes(String action, String stackName, + String template, String inProgressStatus, + boolean terminationProtection) throws Exception { + try (ExecutorService requests = Executors.newSingleThreadExecutor()) { + Future request = requests.submit(() -> { + RequestSpecification form = cfn(action, stackName).formParam("TemplateBody", template); + if (terminationProtection) { + form.formParam("EnableTerminationProtection", "true"); + } + return form.when().post("/"); + }); + try { + assertTrue(provisioningStarted.await(10, TimeUnit.SECONDS), + "stack never reached resource provisioning"); + Response response = request.get(5, TimeUnit.SECONDS); + assertEquals(200, response.statusCode(), response.asString()); + assertThat(response.asString(), containsString("")); + String responseStackId = response.xmlPath().getString("**.find { it.name() == 'StackId' }"); + Response described = cfn("DescribeStacks", stackName).when().post("/"); + assertEquals(200, described.statusCode(), described.asString()); + assertEquals(responseStackId, + described.xmlPath().getString("**.find { it.name() == 'StackId' }")); + assertThat(described.asString(), + containsString("" + inProgressStatus + "")); + if (terminationProtection) { + assertThat(described.asString(), + containsString("true")); + cfn("DeleteStack", stackName).when().post("/").then().statusCode(400) + .body(containsString("cannot be deleted while TerminationProtection is enabled")); + } + return responseStackId; + } finally { + releaseProvisioning.countDown(); + } + } + } + + private static void deleteStack(String stackName) { + cfn("DeleteStack", stackName).when().post("/").then().statusCode(200); + CfnStackWaits.awaitStackDeleted(stackName); + } + + private static String uniqueStackName() { + return PREFIX + UUID.randomUUID().toString().substring(0, 8); + } +} diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationSmallMetadataIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationSmallMetadataIntegrationTest.java index ff0baf3478..28663e3611 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationSmallMetadataIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationSmallMetadataIntegrationTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.cloudformation; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.Test; @@ -254,6 +255,7 @@ class CloudFormationSmallMetadataIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); } private static String describeFlowLogs() { diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationSqsQueuePropertiesIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationSqsQueuePropertiesIntegrationTest.java index 5e7d273a55..3599213963 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationSqsQueuePropertiesIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationSqsQueuePropertiesIntegrationTest.java @@ -1,6 +1,7 @@ package io.github.hectorvent.floci.services.cloudformation; import io.github.hectorvent.floci.core.common.XmlParser; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.Test; @@ -241,6 +242,7 @@ class CloudFormationSqsQueuePropertiesIntegrationTest { } private static String describeStacks(String stack, String expectedStatus) { + CfnStackWaits.awaitStatus(stack, expectedStatus, CFN_AUTH); return given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationSsmParameterIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationSsmParameterIntegrationTest.java index 6960490933..98fc4f2109 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationSsmParameterIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationSsmParameterIntegrationTest.java @@ -76,6 +76,7 @@ class CloudFormationSsmParameterIntegrationTest { .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus("ssm-param-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -130,6 +131,7 @@ class CloudFormationSsmParameterIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus("ssm-missing-param-stack", "CREATE_FAILED"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -182,6 +184,7 @@ class CloudFormationSsmParameterIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus("ssm-secret-ref-param-stack", "CREATE_FAILED"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationStackSetsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationStackSetsIntegrationTest.java index 3ede15277c..63bc5ce7f3 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationStackSetsIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationStackSetsIntegrationTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.cloudformation; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.Test; @@ -130,16 +131,19 @@ class CloudFormationStackSetsIntegrationTest { @Test void singleStackProvisioningLandsInCallerAccount() { String queue = "single-" + UUID.randomUUID().toString().substring(0, 8); + String stackName = "stack-" + queue; given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "CreateStack") - .formParam("StackName", "stack-" + queue) + .formParam("StackName", stackName) .formParam("TemplateBody", queueTemplate(queue)) .header("Authorization", auth(ACCOUNT_B, "cloudformation")) .when().post("/") .then().statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", auth(ACCOUNT_B, "cloudformation")); + // Resource lands in the caller's account, not the default account. assertQueueVisible(ACCOUNT_B, queue); assertQueueAbsent("000000000000", queue); diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationStepFunctionsCleanupIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationStepFunctionsCleanupIntegrationTest.java index e1616acea0..a24dc19f10 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationStepFunctionsCleanupIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationStepFunctionsCleanupIntegrationTest.java @@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.cloudformation; import io.github.hectorvent.floci.core.common.AwsException; import io.github.hectorvent.floci.services.stepfunctions.StepFunctionsService; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.mockito.InjectSpy; @@ -288,6 +289,7 @@ class CloudFormationStepFunctionsCleanupIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); } private static void updateStack(String stackName, String templateBody) { @@ -300,6 +302,7 @@ class CloudFormationStepFunctionsCleanupIntegrationTest { .post("/") .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); } private static void deleteStack(String stackName) { diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationUnsupportedResourceTypeStrictIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationUnsupportedResourceTypeStrictIntegrationTest.java index f9708a1668..2dd1f603cb 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationUnsupportedResourceTypeStrictIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationUnsupportedResourceTypeStrictIntegrationTest.java @@ -44,6 +44,7 @@ class CloudFormationUnsupportedResourceTypeStrictIntegrationTest { } """); + CfnStackWaits.awaitStatus(stackName, "ROLLBACK_COMPLETE", CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationUpdateRollbackParametersTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationUpdateRollbackParametersTest.java index a7aa0fd4e1..309a071509 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationUpdateRollbackParametersTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationUpdateRollbackParametersTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.cloudformation; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.BeforeAll; @@ -74,6 +75,7 @@ class CloudFormationUpdateRollbackParametersTest { .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus("ssm-rollback-stack", "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -99,6 +101,7 @@ class CloudFormationUpdateRollbackParametersTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus("ssm-rollback-stack", "UPDATE_ROLLBACK_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -176,6 +179,7 @@ class CloudFormationUpdateRollbackParametersTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); // This fixture deliberately uses the still-unsupported metric-alarm rollback to exercise // parameter restoration when another resource prevents rollback from completing. given() @@ -190,6 +194,7 @@ class CloudFormationUpdateRollbackParametersTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "UPDATE_ROLLBACK_FAILED"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationUsePreviousTemplateIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationUsePreviousTemplateIntegrationTest.java index 4e1cc0418b..c8d8b80d03 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationUsePreviousTemplateIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationUsePreviousTemplateIntegrationTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.cloudformation; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.quarkus.test.junit.QuarkusTest; import io.restassured.response.Response; import org.junit.jupiter.api.Test; @@ -31,6 +32,7 @@ class CloudFormationUsePreviousTemplateIntegrationTest { .formParam("TemplateBody", TEMPLATE.formatted(queueName)) .when().post("/") .then().statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); } private String visibilityTimeout(String queueName) { @@ -60,6 +62,7 @@ class CloudFormationUsePreviousTemplateIntegrationTest { .when().post("/") .then().statusCode(200); + CfnStackWaits.awaitStatus("use-prev-update", "UPDATE_COMPLETE"); assertEquals("60", visibilityTimeout("use-prev-update-q")); given().contentType(FORM) @@ -88,6 +91,7 @@ class CloudFormationUsePreviousTemplateIntegrationTest { .when().post("/") .then().statusCode(200); + CfnStackWaits.awaitStatus("use-prev-sam", "CREATE_COMPLETE"); given().contentType(FORM) .formParam("Action", "UpdateStack") .formParam("StackName", "use-prev-sam") @@ -97,6 +101,7 @@ class CloudFormationUsePreviousTemplateIntegrationTest { .when().post("/") .then().statusCode(200); + CfnStackWaits.awaitStatus("use-prev-sam", "UPDATE_COMPLETE"); given().contentType(FORM) .formParam("Action", "GetTemplate") .formParam("StackName", "use-prev-sam") diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationVpcDefaultSgAttrIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationVpcDefaultSgAttrIntegrationTest.java index 1a2cd7574e..ac6dcf5044 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationVpcDefaultSgAttrIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationVpcDefaultSgAttrIntegrationTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.cloudformation; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.Test; @@ -48,6 +49,7 @@ class CloudFormationVpcDefaultSgAttrIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationVpcEndpointIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationVpcEndpointIntegrationTest.java index 9d44e40672..247217e4e9 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationVpcEndpointIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationVpcEndpointIntegrationTest.java @@ -160,6 +160,7 @@ class CloudFormationVpcEndpointIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); String stackDescription = given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -239,6 +240,7 @@ class CloudFormationVpcEndpointIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); String stackDescription = given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationVpcPropertiesIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationVpcPropertiesIntegrationTest.java index a1f18cddd8..6f1b802e79 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationVpcPropertiesIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationVpcPropertiesIntegrationTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.cloudformation; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.quarkus.test.junit.QuarkusTest; import io.restassured.path.xml.XmlPath; import io.restassured.response.ValidatableResponse; @@ -128,6 +129,7 @@ class CloudFormationVpcPropertiesIntegrationTest { } private static String describeStacks(String stackName, String expectedStatus) { + CfnStackWaits.awaitStatus(stackName, expectedStatus, CFN_AUTH); return given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationVpcReplacementIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationVpcReplacementIntegrationTest.java index 5cad5fc3cd..064a642e66 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationVpcReplacementIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationVpcReplacementIntegrationTest.java @@ -187,6 +187,7 @@ class CloudFormationVpcReplacementIntegrationTest { } private static String describeStacks(String stack, String expectedStatus) { + CfnStackWaits.awaitStatus(stack, expectedStatus, CFN_AUTH); return given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationWafV2ConfigGetAttIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationWafV2ConfigGetAttIntegrationTest.java index d2581ed60b..e755faa96c 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationWafV2ConfigGetAttIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationWafV2ConfigGetAttIntegrationTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.cloudformation; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; import io.quarkus.test.junit.QuarkusTest; import io.restassured.response.ValidatableResponse; @@ -73,6 +74,7 @@ class CloudFormationWafV2ConfigGetAttIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); String describeBody = given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -140,6 +142,7 @@ class CloudFormationWafV2ConfigGetAttIntegrationTest { .then() .statusCode(200); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -186,6 +189,7 @@ class CloudFormationWafV2ConfigGetAttIntegrationTest { createStack(stackName, template); + CfnStackWaits.awaitStatus(stackName, "ROLLBACK_COMPLETE", CFN_AUTH); describeStackEvents(stackName) .body(containsString("CREATE_FAILED")) .body(containsString( @@ -211,6 +215,7 @@ class CloudFormationWafV2ConfigGetAttIntegrationTest { createStack(stackName, template); + CfnStackWaits.awaitStatus(stackName, "ROLLBACK_COMPLETE", CFN_AUTH); describeStackEvents(stackName) .body(containsString("CREATE_FAILED")) .body(containsString( @@ -239,6 +244,7 @@ class CloudFormationWafV2ConfigGetAttIntegrationTest { createStack(stackName, template); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", CFN_AUTH); given() .contentType(CONFIG_JSON) .header("X-Amz-Target", CONFIG_TARGET_PREFIX + "DescribeConfigRules") diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationWafV2IpSetIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationWafV2IpSetIntegrationTest.java index 65af79e9d4..616d9476e2 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationWafV2IpSetIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationWafV2IpSetIntegrationTest.java @@ -1,6 +1,7 @@ package io.github.hectorvent.floci.services.cloudformation; import io.github.hectorvent.floci.testing.CfnRequests; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; import io.quarkus.test.junit.QuarkusTest; import io.restassured.path.xml.XmlPath; @@ -44,6 +45,7 @@ class CloudFormationWafV2IpSetIntegrationTest { String nameB = "cfn-ipset-b-" + suffix; cfn("CreateStack", stackName, template(nameA, "\"192.0.2.1/32\"")); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); String created = describeStack(stackName) .body(containsString("CREATE_COMPLETE")) .extract().asString(); @@ -58,6 +60,7 @@ class CloudFormationWafV2IpSetIntegrationTest { .body("IPSet.Addresses", contains("192.0.2.1/32")); cfn("UpdateStack", stackName, template(nameA, "\"198.51.100.0/24\"")); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); String addressesUpdated = describeStack(stackName) .body(containsString("UPDATE_COMPLETE")) .extract().asString(); @@ -67,6 +70,7 @@ class CloudFormationWafV2IpSetIntegrationTest { ipSet(nameA, id).body("IPSet.Addresses", contains("198.51.100.0/24")); cfn("UpdateStack", stackName, template(nameB, "\"198.51.100.0/24\"")); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); String replaced = describeStack(stackName) .body(containsString("UPDATE_COMPLETE")) .body(not(containsString("ROLLBACK"))) @@ -107,6 +111,7 @@ class CloudFormationWafV2IpSetIntegrationTest { cfn("CreateStack", stackName, template); + CfnStackWaits.awaitStatus(stackName, "ROLLBACK_COMPLETE"); describeStackEvents(stackName) .body(containsString("CREATE_FAILED")) .body(containsString( @@ -138,6 +143,7 @@ class CloudFormationWafV2IpSetIntegrationTest { """; cfn("CreateStack", stackName, template); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); String created = describeStack(stackName) .body(containsString("CREATE_COMPLETE")) .extract().asString(); diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationWafV2WebAclAssociationIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationWafV2WebAclAssociationIntegrationTest.java index 4c1853459e..a760251692 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationWafV2WebAclAssociationIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationWafV2WebAclAssociationIntegrationTest.java @@ -1,6 +1,7 @@ package io.github.hectorvent.floci.services.cloudformation; import io.github.hectorvent.floci.testing.CfnRequests; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; import io.quarkus.test.junit.QuarkusTest; import io.restassured.path.xml.XmlPath; @@ -41,6 +42,7 @@ class CloudFormationWafV2WebAclAssociationIntegrationTest { String stackName = "cfn-wafv2-assoc-" + suffix; cfn("CreateStack", stackName, template(suffix, "AclA")); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); String created = describeStack(stackName) .body(containsString("CREATE_COMPLETE")) .extract().asString(); @@ -52,6 +54,7 @@ class CloudFormationWafV2WebAclAssociationIntegrationTest { webAclForResource(poolArn).body("WebACL.ARN", equalTo(aclAArn)); cfn("UpdateStack", stackName, template(suffix, "AclB")); + CfnStackWaits.awaitStatus(stackName, "UPDATE_COMPLETE"); String updated = describeStack(stackName) .body(containsString("UPDATE_COMPLETE")) .body(not(containsString("ROLLBACK"))) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CodePipelineCfnIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CodePipelineCfnIntegrationTest.java index 89046cf87b..cdc2c74bff 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CodePipelineCfnIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CodePipelineCfnIntegrationTest.java @@ -81,6 +81,7 @@ class CodePipelineCfnIntegrationTest { .formParam("TemplateBody", TEMPLATE) .when().post("/").then().statusCode(200); + CfnStackWaits.awaitStatus(STACK, "CREATE_COMPLETE"); String stacks = given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CognitoCfnIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CognitoCfnIntegrationTest.java index 6ec9081f8c..a8b0945a85 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CognitoCfnIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CognitoCfnIntegrationTest.java @@ -712,6 +712,7 @@ class CognitoCfnIntegrationTest { } private static String describeStacks(String stack, String expectedStatus) { + CfnStackWaits.awaitStatus(stack, expectedStatus, CFN_AUTH); return given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/ElastiCacheServerlessCfnIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/ElastiCacheServerlessCfnIntegrationTest.java index 351d5515f7..70732f6a65 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/ElastiCacheServerlessCfnIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/ElastiCacheServerlessCfnIntegrationTest.java @@ -130,6 +130,7 @@ class ElastiCacheServerlessCfnIntegrationTest { } private static String describeStacks(String stack, String expectedStatus) { + CfnStackWaits.awaitStatus(stack, expectedStatus, CFN_AUTH); return given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/GuardDutyMalwareProtectionPlanCfnIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/GuardDutyMalwareProtectionPlanCfnIntegrationTest.java index 72c9dfdf0c..03bddcec35 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/GuardDutyMalwareProtectionPlanCfnIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/GuardDutyMalwareProtectionPlanCfnIntegrationTest.java @@ -146,6 +146,7 @@ class GuardDutyMalwareProtectionPlanCfnIntegrationTest { given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH) .formParam("Action", "CreateStack").formParam("StackName", stack).formParam("TemplateBody", template) .when().post("/").then().statusCode(200); + CfnStackWaits.awaitStatus(stack, "CREATE_COMPLETE", CFN_AUTH); String xml = given().contentType("application/x-www-form-urlencoded").header("Authorization", CFN_AUTH) .formParam("Action", "DescribeStacks").formParam("StackName", stack) .when().post("/").then().statusCode(200) @@ -299,6 +300,7 @@ class GuardDutyMalwareProtectionPlanCfnIntegrationTest { } private static String describe(String stack, String expectedStatus) { + CfnStackWaits.awaitStatus(stack, expectedStatus, CFN_AUTH); return given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) @@ -328,6 +330,7 @@ class GuardDutyMalwareProtectionPlanCfnIntegrationTest { } private static String describeStacks(String expectedStatus) { + CfnStackWaits.awaitStatus(STACK, expectedStatus, CFN_AUTH); return given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/IotCfnIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/IotCfnIntegrationTest.java index bae2c1024a..d1a9babf2a 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/IotCfnIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/IotCfnIntegrationTest.java @@ -250,6 +250,7 @@ class IotCfnIntegrationTest { } private static String describeStacks(String expectedStatus) { + CfnStackWaits.awaitStatus(STACK, expectedStatus, CFN_AUTH); return given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/IotDomainConfigurationCfnIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/IotDomainConfigurationCfnIntegrationTest.java index 525325f8d8..c0b9030078 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/IotDomainConfigurationCfnIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/IotDomainConfigurationCfnIntegrationTest.java @@ -126,6 +126,7 @@ class IotDomainConfigurationCfnIntegrationTest { } private static String describeStacks(String expectedStatus) { + CfnStackWaits.awaitStatus(STACK, expectedStatus, CFN_AUTH); return given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/RedshiftServerlessCfnIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/RedshiftServerlessCfnIntegrationTest.java index 2a4aca41c1..bb833093a2 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/RedshiftServerlessCfnIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/RedshiftServerlessCfnIntegrationTest.java @@ -214,6 +214,8 @@ class RedshiftServerlessCfnIntegrationTest { } private static String describeStacks(String expectedStatus) { + CfnStackWaits.StackState state = CfnStackWaits.awaitTerminal(STACK, CFN_AUTH); + assertEquals(expectedStatus, state.status(), state.reason()); return given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/SamTransformIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/SamTransformIntegrationTest.java index cac561b9c7..6447fcebfa 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/SamTransformIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/SamTransformIntegrationTest.java @@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.cloudformation; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import io.github.hectorvent.floci.core.common.XmlParser; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.AfterEach; @@ -885,6 +886,7 @@ class SamTransformIntegrationTest { .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -939,6 +941,7 @@ class SamTransformIntegrationTest { .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -1004,6 +1007,7 @@ class SamTransformIntegrationTest { .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -1633,6 +1637,7 @@ class SamTransformIntegrationTest { .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -1685,6 +1690,7 @@ class SamTransformIntegrationTest { .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") @@ -1742,6 +1748,7 @@ class SamTransformIntegrationTest { .statusCode(200) .body(containsString("")); + CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE"); given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/SnsFifoThroughputScopeCfnIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/SnsFifoThroughputScopeCfnIntegrationTest.java index 8e1537c79b..36d784fbfc 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/SnsFifoThroughputScopeCfnIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/SnsFifoThroughputScopeCfnIntegrationTest.java @@ -123,6 +123,7 @@ class SnsFifoThroughputScopeCfnIntegrationTest { } private static String describeStacks(String expectedStatus) { + CfnStackWaits.awaitStatus(STACK, expectedStatus, CFN_AUTH); return given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/SnsTopicPolicyCfnIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/SnsTopicPolicyCfnIntegrationTest.java index eee51af3d5..557baff91c 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/SnsTopicPolicyCfnIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/SnsTopicPolicyCfnIntegrationTest.java @@ -120,6 +120,8 @@ class SnsTopicPolicyCfnIntegrationTest { } private static String describeStacks(String expectedStatus) { + CfnStackWaits.StackState state = CfnStackWaits.awaitTerminal(STACK, CFN_AUTH); + assertEquals(expectedStatus, state.status(), state.reason()); return given() .contentType("application/x-www-form-urlencoded") .header("Authorization", CFN_AUTH) diff --git a/src/test/java/io/github/hectorvent/floci/services/dynamodb/backend/DynamoDbLocalBackendIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/dynamodb/backend/DynamoDbLocalBackendIntegrationTest.java index 0a0f61d70f..cfe22641ae 100644 --- a/src/test/java/io/github/hectorvent/floci/services/dynamodb/backend/DynamoDbLocalBackendIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/dynamodb/backend/DynamoDbLocalBackendIntegrationTest.java @@ -9,6 +9,7 @@ import io.github.hectorvent.floci.services.dynamodb.backend.DynamoDbStreamReader import io.github.hectorvent.floci.services.dynamodb.backend.DynamoDbStreamReader.RecordsPage; import io.github.hectorvent.floci.services.dynamodb.backend.DynamoDbStreamReader.Shard; import io.github.hectorvent.floci.services.dynamodb.backend.DynamoDbStreamReader.Stream; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; import io.github.hectorvent.floci.testing.TestAccounts; import io.quarkus.test.junit.QuarkusTest; @@ -282,6 +283,7 @@ class DynamoDbLocalBackendIntegrationTest { cloudFormation(A_EAST, "CreateStack", stack, template); // The stack stays in Floci; its table is removed from Local with the others. created.add(new CreatedTable(A_EAST, table)); + CfnStackWaits.awaitStatus(stack, "CREATE_COMPLETE", A_EAST.authorization("cloudformation")); cloudFormation(A_EAST, "DescribeStacks", stack, null) .body(containsString("CREATE_COMPLETE")); diff --git a/src/test/java/io/github/hectorvent/floci/services/ec2/AutoScalingConfigurationUserDataIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ec2/AutoScalingConfigurationUserDataIntegrationTest.java index c9874708ce..ba390795fb 100644 --- a/src/test/java/io/github/hectorvent/floci/services/ec2/AutoScalingConfigurationUserDataIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/ec2/AutoScalingConfigurationUserDataIntegrationTest.java @@ -4,6 +4,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig; import io.github.hectorvent.floci.services.autoscaling.AutoScalingReconciler; import io.github.hectorvent.floci.services.autoscaling.AutoScalingService; import io.github.hectorvent.floci.services.ec2.model.Instance; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.mockito.InjectSpy; import io.restassured.specification.RequestSpecification; @@ -55,6 +56,7 @@ class AutoScalingConfigurationUserDataIntegrationTest { createConfiguration(source, name, encoded); try { if (!source.equals("query")) { + CfnStackWaits.awaitStatus(name, "CREATE_COMPLETE"); String status = request("cloudformation", "DescribeStacks").formParam("StackName", name) .post("/").then().statusCode(200).extract().xmlPath() .getString("DescribeStacksResponse.DescribeStacksResult.Stacks.member.StackStatus"); @@ -126,6 +128,7 @@ class AutoScalingConfigurationUserDataIntegrationTest { } else { createConfiguration(source, name, data); try { + CfnStackWaits.awaitStatus(name, "ROLLBACK_COMPLETE"); String status = request("cloudformation", "DescribeStacks").formParam("StackName", name) .post("/").then().statusCode(200).extract().xmlPath() .getString("DescribeStacksResponse.DescribeStacksResult.Stacks.member.StackStatus"); diff --git a/src/test/java/io/github/hectorvent/floci/services/ecs/EcsContainerInsightsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ecs/EcsContainerInsightsIntegrationTest.java index 0142c25e25..ae3fcc3473 100644 --- a/src/test/java/io/github/hectorvent/floci/services/ecs/EcsContainerInsightsIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/ecs/EcsContainerInsightsIntegrationTest.java @@ -64,6 +64,7 @@ class EcsContainerInsightsIntegrationTest { .formParam("StackName", cluster) .formParam("TemplateBody", template) .post("/").then().statusCode(200); + awaitStackStatus(cluster, "CREATE_COMPLETE"); given().contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") .formParam("StackName", cluster) diff --git a/src/test/java/io/github/hectorvent/floci/services/elbv2/ElbV2DefaultAttributesIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/elbv2/ElbV2DefaultAttributesIntegrationTest.java index 57ed54c758..129ec609a4 100644 --- a/src/test/java/io/github/hectorvent/floci/services/elbv2/ElbV2DefaultAttributesIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/elbv2/ElbV2DefaultAttributesIntegrationTest.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.elbv2; +import io.github.hectorvent.floci.testing.CfnStackWaits; import io.quarkus.test.junit.QuarkusTest; import io.restassured.response.Response; import org.junit.jupiter.api.Test; @@ -202,6 +203,7 @@ class ElbV2DefaultAttributesIntegrationTest { given().formParam("Action", "CreateStack").formParam("StackName", stack) .formParam("TemplateBody", template.formatted(arn, "200")) .when().post("/").then().statusCode(200); + CfnStackWaits.awaitStatus(stack, "CREATE_COMPLETE"); given().formParam("Action", "DescribeStacks").formParam("StackName", stack) .when().post("/").then().statusCode(200) .body("DescribeStacksResponse.DescribeStacksResult.Stacks.member.StackStatus", equalTo("CREATE_COMPLETE")); @@ -214,6 +216,7 @@ class ElbV2DefaultAttributesIntegrationTest { given().formParam("Action", "UpdateStack").formParam("StackName", stack) .formParam("TemplateBody", template.formatted(arn, "201")) .when().post("/").then().statusCode(200); + CfnStackWaits.awaitStatus(stack, "UPDATE_COMPLETE"); given().formParam("Action", "DescribeStacks").formParam("StackName", stack) .when().post("/").then().statusCode(200) .body("DescribeStacksResponse.DescribeStacksResult.Stacks.member.StackStatus", equalTo("UPDATE_COMPLETE")); @@ -228,6 +231,7 @@ class ElbV2DefaultAttributesIntegrationTest { try { given().formParam("Action", "DeleteStack").formParam("StackName", stack) .when().post("/").then().statusCode(200); + CfnStackWaits.awaitStackDeleted(stack); given().header("Authorization", AUTH).formParam("Action", "DescribeListeners") .formParam("LoadBalancerArn", arn).when().post("/").then().statusCode(200) .body("DescribeListenersResponse.DescribeListenersResult.Listeners.member.size()", equalTo(0)); diff --git a/src/test/java/io/github/hectorvent/floci/testing/CfnStackWaits.java b/src/test/java/io/github/hectorvent/floci/testing/CfnStackWaits.java index 9196b3f0b7..3ceb73a3ab 100644 --- a/src/test/java/io/github/hectorvent/floci/testing/CfnStackWaits.java +++ b/src/test/java/io/github/hectorvent/floci/testing/CfnStackWaits.java @@ -88,14 +88,21 @@ public final class CfnStackWaits { * seconds without the expected status. */ public static StackState awaitStatus(String stackName, String expectedStatus) { + return awaitStatus(stackName, expectedStatus, null); + } + + public static StackState awaitStatus(String stackName, String expectedStatus, String authorization) { long deadline = System.currentTimeMillis() + 10_000; StackState last = new StackState(null, ""); while (System.currentTimeMillis() < deadline) { - Response response = given() + RequestSpecification request = given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") - .formParam("StackName", stackName) - .when().post("/"); + .formParam("StackName", stackName); + if (authorization != null) { + request.header("Authorization", authorization); + } + Response response = request.when().post("/"); if (response.statusCode() != 200) { fail("DescribeStacks " + stackName + " answered " + response.statusCode() + ": " + response.asString()); }