diff --git a/src/test/java/io/floci/aws/services/cloudformation/CfnReplacementIntegrationTest.java b/src/test/java/io/floci/aws/services/cloudformation/CfnReplacementIntegrationTest.java index 34b7b3e32d..8017d2d577 100644 --- a/src/test/java/io/floci/aws/services/cloudformation/CfnReplacementIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/cloudformation/CfnReplacementIntegrationTest.java @@ -4,6 +4,7 @@ import io.floci.aws.services.cloudformation.model.Stack; import io.floci.aws.testing.AwsTestClients; import io.floci.aws.testing.CfnStackWaits; import io.floci.aws.testing.DockerAvailability; +import io.floci.aws.testing.EcrRegistryWarmup; import io.quarkus.test.junit.QuarkusTest; import io.restassured.http.ContentType; import jakarta.inject.Inject; @@ -292,6 +293,9 @@ class CfnReplacementIntegrationTest { if (row.needsDocker()) { Assumptions.assumeTrue(DockerAvailability.isAvailable(), "Docker is required for the cache data plane"); } + if (row.before().contains("\"AWS::ECR::Repository\"")) { + EcrRegistryWarmup.warm(); + } String stack = "repl-" + Long.toString(System.nanoTime(), 36); try (CloudFormationClient client = AwsTestClients.create( CloudFormationClient.builder(), "test", Region.US_EAST_1)) { @@ -658,6 +662,7 @@ class CfnReplacementIntegrationTest { @Test void aRenamedEcrRepositoryLeavesNoRepositoryUnderTheOldName() throws Exception { + EcrRegistryWarmup.warm(); String suffix = Long.toString(System.nanoTime(), 36); String stack = "repl-ecr-" + suffix; String first = "repl-ecr-a-" + suffix; @@ -690,6 +695,7 @@ class CfnReplacementIntegrationTest { @Test void aRenamedEcrRepositoryThatStillHoldsAnImageIsKept() throws Exception { Assumptions.assumeTrue(DockerAvailability.isAvailable(), "Docker is required for the registry data plane"); + EcrRegistryWarmup.warm(); String suffix = Long.toString(System.nanoTime(), 36); String stack = "repl-ecr-full-" + suffix; String first = "repl-ecr-full-a-" + suffix; diff --git a/src/test/java/io/floci/aws/services/cloudformation/CfnUnchangedResourceUpdateIntegrationTest.java b/src/test/java/io/floci/aws/services/cloudformation/CfnUnchangedResourceUpdateIntegrationTest.java index 172c0972a6..54ed30da8a 100644 --- a/src/test/java/io/floci/aws/services/cloudformation/CfnUnchangedResourceUpdateIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/cloudformation/CfnUnchangedResourceUpdateIntegrationTest.java @@ -2,6 +2,7 @@ package io.floci.aws.services.cloudformation; import io.floci.aws.core.common.XmlParser; import io.floci.aws.testing.CfnStackWaits; +import io.floci.aws.testing.EcrRegistryWarmup; import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.Test; @@ -513,6 +514,7 @@ class CfnUnchangedResourceUpdateIntegrationTest { @Test void ecrRepository() { + EcrRegistryWarmup.warm(); assertUnchangedResourceSurvivesUpdate("ecr", """ "Named": { "Type": "AWS::ECR::Repository", diff --git a/src/test/java/io/floci/aws/services/cloudformation/CloudFormationIntegrationTest.java b/src/test/java/io/floci/aws/services/cloudformation/CloudFormationIntegrationTest.java index 6788f98f46..e2acff963c 100644 --- a/src/test/java/io/floci/aws/services/cloudformation/CloudFormationIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/cloudformation/CloudFormationIntegrationTest.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.floci.aws.services.cloudformation.model.Stack; import io.floci.aws.services.ec2.Ec2Service; import io.floci.aws.testing.CfnStackWaits; +import io.floci.aws.testing.EcrRegistryWarmup; import io.floci.aws.testing.LambdaCodeFixtures; import io.floci.aws.testing.MutableClock; import io.floci.aws.testing.RestAssuredJsonUtils; @@ -3471,6 +3472,7 @@ class CloudFormationIntegrationTest { @Test void createStack_ecrAutoName_isLowercase() { + EcrRegistryWarmup.warm(); // ECR repository names must be lowercase. // See: https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-ecr-repository.html String template = """ diff --git a/src/test/java/io/floci/aws/services/cloudformation/CloudFormationNamedResourceIdenticalUpdateIntegrationTest.java b/src/test/java/io/floci/aws/services/cloudformation/CloudFormationNamedResourceIdenticalUpdateIntegrationTest.java index 6360efb21c..6f8d04eaea 100644 --- a/src/test/java/io/floci/aws/services/cloudformation/CloudFormationNamedResourceIdenticalUpdateIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/cloudformation/CloudFormationNamedResourceIdenticalUpdateIntegrationTest.java @@ -2,6 +2,7 @@ package io.floci.aws.services.cloudformation; import io.floci.aws.core.common.XmlParser; import io.floci.aws.testing.CfnStackWaits; +import io.floci.aws.testing.EcrRegistryWarmup; import io.quarkus.test.junit.QuarkusTest; import io.restassured.response.Response; import io.restassured.specification.RequestSpecification; @@ -147,6 +148,9 @@ class CloudFormationNamedResourceIdenticalUpdateIntegrationTest { @ParameterizedTest @MethodSource("cases") void identicalUpdateIsANoOpAndDeleteCleansUp(Case c) { + if (c.template().contains("\"AWS::ECR::Repository\"")) { + EcrRegistryWarmup.warm(); + } String suffix = Long.toString(System.nanoTime(), 36); String stackName = "probe-" + suffix; String template = c.template().replace("%s", suffix); diff --git a/src/test/java/io/floci/aws/testing/EcrRegistryWarmup.java b/src/test/java/io/floci/aws/testing/EcrRegistryWarmup.java new file mode 100644 index 0000000000..eeca4c6e44 --- /dev/null +++ b/src/test/java/io/floci/aws/testing/EcrRegistryWarmup.java @@ -0,0 +1,35 @@ +package io.floci.aws.testing; + +import io.floci.aws.core.common.RequestScopes; +import io.floci.aws.services.ecr.registry.EcrRegistryManager; +import io.quarkus.arc.Arc; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Starts the ECR registry before a stack creates a repository: {@code CreateRepository} starts it inside the request, + * which can take longer than the stack wait. Without Docker there is no registry to start and nothing to wait for. + */ +public final class EcrRegistryWarmup { + + private EcrRegistryWarmup() { + } + + public static void warm() { + if (!dockerAvailable()) { + return; + } + EcrRegistryManager registryManager = Arc.container().instance(EcrRegistryManager.class).get(); + boolean started = RequestScopes.callAs(null, "us-west-2", registryManager::tryEnsureStarted); + assertTrue(started, "ECR registry failed to start"); + } + + private static boolean dockerAvailable() { + try { + return DockerAvailability.isAvailable(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new IllegalStateException("Interrupted while probing Docker", e); + } + } +}