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.
This commit is contained in:
Olamide Kosile authored and GitHub committed 2026-09-12 18:50:20 -05:00
1 parent 8963c665eb
commit ec2ab07689
1 file changed
+33 -11
@@ -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) {