test(cloudformation): start the ECR registry before every ECR stack test (#9672)

This commit is contained in:
Oleksandr Nikolaichuk authored and GitHub committed 2026-11-28 15:54:16 -04:00
1 parent faa4892239
commit ab5759529f
5 files changed
+49

No files matched your search

@@ -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;
@@ -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",
@@ -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 = """
@@ -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);
@@ -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);
}
}
}