From fafe5476cd248b1c28ea1d24f279fd1f2c2c7cc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C5=A9=20Th=E1=BA=BF=20Huy?= <31652864+vuthehuyht@users.noreply.github.com> Date: Wed, 23 Sep 2026 12:14:59 +0700 Subject: [PATCH] fix(cloudformation): await stack completion after ExecuteChangeSet in integration tests (#4078) --- .../CloudFormationIntegrationTest.java | 39 +++++++++---------- 1 file changed, 18 insertions(+), 21 deletions(-) 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 c3a4615043..662dfbe298 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 @@ -86,9 +86,14 @@ class CloudFormationIntegrationTest { * or after ten seconds, so a test can assert on the deleted resources afterwards. */ private static void awaitStackDeleted(String stackNameOrArn) { + awaitStackStatus(stackNameOrArn, "DELETE_COMPLETE"); + } + + private static void awaitStackStatus(String stackNameOrArn, String expectedStatus) { long deadline = System.currentTimeMillis() + 10_000; + String statusXml = ""; while (System.currentTimeMillis() < deadline) { - String statusXml = given() + statusXml = given() .contentType("application/x-www-form-urlencoded") .formParam("Action", "DescribeStacks") .formParam("StackName", stackNameOrArn) @@ -96,18 +101,23 @@ class CloudFormationIntegrationTest { .post("/") .then() .extract().body().asString(); - assertThat(statusXml, not(containsString("DELETE_FAILED"))); - if (statusXml.contains("DELETE_COMPLETE") || statusXml.contains("does not exist")) { + if ("DELETE_COMPLETE".equals(expectedStatus)) { + assertThat(statusXml, not(containsString("DELETE_FAILED"))); + if (statusXml.contains("DELETE_COMPLETE") + || statusXml.contains("does not exist")) { + return; + } + } else if (statusXml.contains("" + expectedStatus + "")) { return; } try { - Thread.sleep(200); + Thread.sleep(50); } catch (InterruptedException e) { Thread.currentThread().interrupt(); - throw new AssertionError("Interrupted while waiting for stack " + stackNameOrArn + " to be deleted", e); + throw new AssertionError("Interrupted while waiting for stack " + stackNameOrArn + " to reach " + expectedStatus, e); } } - throw new AssertionError("Stack " + stackNameOrArn + " did not reach DELETE_COMPLETE within timeout"); + assertThat(statusXml, containsString("" + expectedStatus + "")); } private static String firstPhysicalResourceId(String xml) { @@ -4165,15 +4175,7 @@ class CloudFormationIntegrationTest { .statusCode(200); // 4. Stack should reach CREATE_COMPLETE - given() - .contentType("application/x-www-form-urlencoded") - .formParam("Action", "DescribeStacks") - .formParam("StackName", "cfn-cs-arn-stack") - .when() - .post("/") - .then() - .statusCode(200) - .body(containsString("CREATE_COMPLETE")); + awaitStackStatus("cfn-cs-arn-stack", "CREATE_COMPLETE"); } @Test @@ -10972,12 +10974,7 @@ class CloudFormationIntegrationTest { .formParam("ChangeSetName", "deploy-attempt-2") .when().post("/").then().statusCode(200); - given() - .contentType("application/x-www-form-urlencoded") - .formParam("Action", "DescribeStacks") - .formParam("StackName", stackName) - .when().post("/") - .then().statusCode(200).body(containsString("CREATE_COMPLETE")); + awaitStackStatus(stackName, "CREATE_COMPLETE"); } @Test