From ec2ab07689a81ed6433c8bfb136164136e94eced Mon Sep 17 00:00:00 2001 From: Olamide Kosile <64154023+Mide69@users.noreply.github.com> Date: Sun, 13 Sep 2026 00:50:20 +0100 Subject: [PATCH] fix(test): wait for DeleteStack to actually complete in CloudFront policies test (#3473) Fixes #3365. distributionRefToAResponseHeadersPolicyInTheSameStackResolves intermittently failed CI with "Expected status code <400> but was <200>" on the DescribeStacks call immediately following DeleteStack. CloudFormationService.deleteStack() dispatches the actual resource cleanup onto an executor and returns before it completes (documented on the method itself), so a DescribeStacks call made immediately after DeleteStack's 200 races that executor. CloudFormationIntegrationTest already has an awaitStackDeleted helper for exactly this race; this test class's own deleteStack helper never got it and asserted synchronously instead. Adds the same poll-until-gone helper used elsewhere in the suite. Full cloudformation package regression (1660 tests) passes clean aside from the three known pre-existing flaky failures already documented elsewhere in this repo (two 30s SocketTimeoutExceptions on ecrAutoName_isLowercase and samFunction_withAutoPublishAlias_createsVersionAndAlias, and one staging-directory extraction race on samFunction_withoutAutoPublishAlias_createsNoAlias), none of which touch CloudFront or DeleteStack. --- ...tionCloudFrontPoliciesIntegrationTest.java | 44 ++++++++++++++----- 1 file changed, 33 insertions(+), 11 deletions(-) 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 5917473127..645511b8e4 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 @@ -16,7 +16,6 @@ import java.util.List; import java.util.Map; import static io.restassured.RestAssured.given; -import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -267,16 +266,39 @@ class CloudFormationCloudFrontPoliciesIntegrationTest { .post("/") .then() .statusCode(200); - given() - .contentType("application/x-www-form-urlencoded") - .header("Authorization", CFN_AUTH) - .formParam("Action", "DescribeStacks") - .formParam("StackName", stackName) - .when() - .post("/") - .then() - .statusCode(400) - .body(containsString("Stack with id " + stackName + " does not exist")); + awaitStackDeleted(stackName); + } + + /** + * github.com/floci-io/floci/issues/3365: DeleteStack answers before the stack is actually + * gone - deletion runs on an executor (CloudFormationService.deleteStack) - so a DescribeStacks + * call made immediately after DeleteStack's 200 races that executor and intermittently still + * finds the stack. Polls until DescribeStacks reports the stack unknown, matching the + * awaitStackDeleted helper CloudFormationIntegrationTest already uses for the same race. + */ + private static void awaitStackDeleted(String stackName) { + long deadline = System.currentTimeMillis() + 10_000; + while (System.currentTimeMillis() < deadline) { + String body = given() + .contentType("application/x-www-form-urlencoded") + .header("Authorization", CFN_AUTH) + .formParam("Action", "DescribeStacks") + .formParam("StackName", stackName) + .when() + .post("/") + .then() + .extract().body().asString(); + if (body.contains("Stack with id " + stackName + " does not exist")) { + return; + } + try { + Thread.sleep(200); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new AssertionError("Interrupted while waiting for stack " + stackName + " to be deleted", e); + } + } + fail("Stack " + stackName + " did not become unknown to DescribeStacks within timeout"); } private static String describeStacks(String stackName) {