From 0bb6c6e76afdabd064812efc164baa791ae21049 Mon Sep 17 00:00:00 2001 From: Hector Ventura Date: Sat, 20 Jun 2026 13:03:13 -0500 Subject: [PATCH] test(ec2): stop describeDefaultSecurityGroup flaking on shared store (#1477) Filter DescribeSecurityGroups by group-name + vpc-id instead of assuming the default group is item[0] of an unfiltered list, and tear down the stack the CFN deleteStack test recreates. Both prevent flaky failures caused by other tests leaving security groups behind in the shared in-memory EC2 store. --- .../cloudformation/CloudFormationIntegrationTest.java | 9 +++++++++ .../floci/services/ec2/Ec2IntegrationTest.java | 8 ++++++++ 2 files changed, 17 insertions(+) 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 10549ced6a..0fb1b2b34f 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 @@ -5284,6 +5284,15 @@ class CloudFormationIntegrationTest { .formParam("TemplateBody", template) .when().post("/") .then().statusCode(200); + + // 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. + given() + .formParam("Action", "DeleteStack") + .formParam("Version", "2010-05-15") + .formParam("StackName", stackName) + .when().post("/") + .then().statusCode(200); } @Test diff --git a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2IntegrationTest.java index 064a9c3fb2..5d0f9aa6b5 100644 --- a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2IntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2IntegrationTest.java @@ -92,8 +92,16 @@ class Ec2IntegrationTest { @Test @Order(3) void describeDefaultSecurityGroup() { + // Filter to the default VPC's default group rather than assuming it is item[0] of an + // unfiltered list: DescribeSecurityGroups returns groups in the store's iteration order, + // so any other group in this region (e.g. one left behind by another test class sharing + // the in-memory EC2 store) could otherwise land at item[0] and flake this assertion. given() .formParam("Action", "DescribeSecurityGroups") + .formParam("Filter.1.Name", "group-name") + .formParam("Filter.1.Value.1", "default") + .formParam("Filter.2.Name", "vpc-id") + .formParam("Filter.2.Value.1", "vpc-default") .header("Authorization", AUTH_HEADER) .when() .post("/")