From 67a619d58ee9d236bb451600c409be213e9c66ee Mon Sep 17 00:00:00 2001 From: Priamo Germosen <6233424+pgermosen@users.noreply.github.com> Date: Tue, 24 Nov 2026 11:02:42 -0400 Subject: [PATCH] test: build the EmulatorConfig mapping in one plain test class at a time (#9358) Now that the plain test classes run four at a time, two classes that build the EmulatorConfig mapping with a SmallRyeConfigBuilder at once fail with NoClassDefFoundError for a nested group's generated class (EmulatorConfig$AmazonMqServiceConfig$$CMImpl). ImageResolverEnvConfigTest and WorkingDirectoryAccessDockerIntegrationTest fail that way whenever a shard holds both. The eight plain classes that build it take a new ParallelLocks.CONFIG_MAPPING lock, and ParallelLocksInventoryTest fails a plain class that builds it without the lock. --- AGENTS.md | 6 ++++-- .../config/EmulatorConfigDsqlBackendTest.java | 1 + ...rPoolSaturationNightlyIntegrationTest.java | 3 +++ ...BuiltHelperImageDockerIntegrationTest.java | 3 +++ .../codepipeline/CodePipelineServiceTest.java | 3 +++ .../CognitoSignUpTriggerReentrancyTest.java | 1 + .../launcher/ImageResolverEnvConfigTest.java | 3 +++ ...gDirectoryAccessDockerIntegrationTest.java | 3 +++ .../route53/Route53NameserverConfigTest.java | 3 +++ .../io/floci/aws/testing/ParallelLocks.java | 8 ++++++++ .../testing/ParallelLocksInventoryTest.java | 20 ++++++++++++++++++- 11 files changed, 51 insertions(+), 3 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 98f4a0683d..03ed3975f9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -261,8 +261,10 @@ Guidelines: - Plain test classes (no `@QuarkusTest`) run four at a time in CI, in a Surefire pass before the Quarkus classes. A plain class that opens a socket declares `@ResourceLock(ParallelLocks.PORTS)`: the default mode when it releases a port and binds or dials it later (`FreePorts`, a port expected - to refuse), `mode = ResourceAccessMode.READ` otherwise. `ParallelLocksInventoryTest` enforces it. A - class that shares other process-wide state takes a lock named in `ParallelLocks` (`TLS_CONFIG` for + to refuse), `mode = ResourceAccessMode.READ` otherwise. A plain class that builds the + `EmulatorConfig` mapping with a `SmallRyeConfigBuilder` declares + `@ResourceLock(ParallelLocks.CONFIG_MAPPING)`. `ParallelLocksInventoryTest` enforces both. A class + that shares other process-wide state takes a lock named in `ParallelLocks` (`TLS_CONFIG` for `TlsConfigSource`) - Prefer package-private constructors for testability - Integration tests may use ordered execution when stateful behavior requires it diff --git a/src/test/java/io/floci/aws/config/EmulatorConfigDsqlBackendTest.java b/src/test/java/io/floci/aws/config/EmulatorConfigDsqlBackendTest.java index c781afc5cc..367fdfe529 100644 --- a/src/test/java/io/floci/aws/config/EmulatorConfigDsqlBackendTest.java +++ b/src/test/java/io/floci/aws/config/EmulatorConfigDsqlBackendTest.java @@ -17,6 +17,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @ResourceLock(ParallelLocks.TLS_CONFIG) +@ResourceLock(ParallelLocks.CONFIG_MAPPING) class EmulatorConfigDsqlBackendTest { @Test diff --git a/src/test/java/io/floci/aws/core/common/docker/DockerPoolSaturationNightlyIntegrationTest.java b/src/test/java/io/floci/aws/core/common/docker/DockerPoolSaturationNightlyIntegrationTest.java index 03ff6f5905..e52ba40479 100644 --- a/src/test/java/io/floci/aws/core/common/docker/DockerPoolSaturationNightlyIntegrationTest.java +++ b/src/test/java/io/floci/aws/core/common/docker/DockerPoolSaturationNightlyIntegrationTest.java @@ -11,6 +11,7 @@ import com.github.dockerjava.core.DefaultDockerClientConfig; import com.github.dockerjava.core.DockerClientImpl; import io.floci.aws.config.EmulatorConfig; import io.floci.aws.testing.DockerAvailability; +import io.floci.aws.testing.ParallelLocks; import io.floci.aws.testing.TestImages; import io.smallrye.config.SmallRyeConfigBuilder; import org.apache.hc.core5.http.ConnectionRequestTimeoutException; @@ -21,6 +22,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; import org.junit.jupiter.api.condition.EnabledIfSystemProperty; +import org.junit.jupiter.api.parallel.ResourceLock; import java.io.Closeable; import java.io.IOException; @@ -58,6 +60,7 @@ import static org.junit.jupiter.api.Assertions.fail; * three-minute bound fits the default on a hosted runner, so a much larger ramp needs it raised too. */ @EnabledIfSystemProperty(named = "nightly.checks.enabled", matches = "true") +@ResourceLock(ParallelLocks.CONFIG_MAPPING) class DockerPoolSaturationNightlyIntegrationTest { private static final Logger LOG = Logger.getLogger(DockerPoolSaturationNightlyIntegrationTest.class); diff --git a/src/test/java/io/floci/aws/core/common/docker/LocallyBuiltHelperImageDockerIntegrationTest.java b/src/test/java/io/floci/aws/core/common/docker/LocallyBuiltHelperImageDockerIntegrationTest.java index e618dfefe3..7decf93a90 100644 --- a/src/test/java/io/floci/aws/core/common/docker/LocallyBuiltHelperImageDockerIntegrationTest.java +++ b/src/test/java/io/floci/aws/core/common/docker/LocallyBuiltHelperImageDockerIntegrationTest.java @@ -8,9 +8,11 @@ import com.github.dockerjava.core.command.WaitContainerResultCallback; import io.floci.aws.config.EmulatorConfig; import io.floci.aws.core.common.dns.EmbeddedDnsServer; import io.floci.aws.testing.DockerAvailability; +import io.floci.aws.testing.ParallelLocks; import io.smallrye.config.SmallRyeConfigBuilder; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.ResourceLock; import java.io.InputStream; import java.nio.charset.StandardCharsets; @@ -26,6 +28,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; /** Builds and reuses a native helper when the configured Docker daemon answers. */ +@ResourceLock(ParallelLocks.CONFIG_MAPPING) class LocallyBuiltHelperImageDockerIntegrationTest { private static final String BASE = "busybox:1.37.0"; diff --git a/src/test/java/io/floci/aws/services/codepipeline/CodePipelineServiceTest.java b/src/test/java/io/floci/aws/services/codepipeline/CodePipelineServiceTest.java index 5e6f536ee1..2593835f60 100644 --- a/src/test/java/io/floci/aws/services/codepipeline/CodePipelineServiceTest.java +++ b/src/test/java/io/floci/aws/services/codepipeline/CodePipelineServiceTest.java @@ -20,10 +20,12 @@ import io.floci.aws.services.codepipeline.model.CodePipelinePipeline.TransitionS import io.floci.aws.services.lambda.LambdaService; import io.floci.aws.services.s3.S3Service; import io.floci.aws.services.s3.model.S3Object; +import io.floci.aws.testing.ParallelLocks; import io.floci.aws.testing.ThreadStates; import io.smallrye.config.SmallRyeConfigBuilder; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.function.Executable; +import org.junit.jupiter.api.parallel.ResourceLock; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -65,6 +67,7 @@ import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +@ResourceLock(ParallelLocks.CONFIG_MAPPING) class CodePipelineServiceTest { private static final String REGION = "us-east-1"; diff --git a/src/test/java/io/floci/aws/services/cognito/CognitoSignUpTriggerReentrancyTest.java b/src/test/java/io/floci/aws/services/cognito/CognitoSignUpTriggerReentrancyTest.java index 227deaec8b..215d2348be 100644 --- a/src/test/java/io/floci/aws/services/cognito/CognitoSignUpTriggerReentrancyTest.java +++ b/src/test/java/io/floci/aws/services/cognito/CognitoSignUpTriggerReentrancyTest.java @@ -60,6 +60,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @ResourceLock(value = ParallelLocks.PORTS, mode = ResourceAccessMode.READ) +@ResourceLock(ParallelLocks.CONFIG_MAPPING) class CognitoSignUpTriggerReentrancyTest { private static final ObjectMapper MAPPER = new ObjectMapper(); private static final String FUNCTION = "signup-trigger"; diff --git a/src/test/java/io/floci/aws/services/lambda/launcher/ImageResolverEnvConfigTest.java b/src/test/java/io/floci/aws/services/lambda/launcher/ImageResolverEnvConfigTest.java index 7429cfaf32..efd5c43123 100644 --- a/src/test/java/io/floci/aws/services/lambda/launcher/ImageResolverEnvConfigTest.java +++ b/src/test/java/io/floci/aws/services/lambda/launcher/ImageResolverEnvConfigTest.java @@ -1,16 +1,19 @@ package io.floci.aws.services.lambda.launcher; import io.floci.aws.config.EmulatorConfig; +import io.floci.aws.testing.ParallelLocks; import io.smallrye.config.EnvConfigSource; import io.smallrye.config.SmallRyeConfig; import io.smallrye.config.SmallRyeConfigBuilder; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.ResourceLock; import java.util.Map; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; +@ResourceLock(ParallelLocks.CONFIG_MAPPING) class ImageResolverEnvConfigTest { @Test diff --git a/src/test/java/io/floci/aws/services/lambda/launcher/WorkingDirectoryAccessDockerIntegrationTest.java b/src/test/java/io/floci/aws/services/lambda/launcher/WorkingDirectoryAccessDockerIntegrationTest.java index 1c6e118012..cb96fe8ae8 100644 --- a/src/test/java/io/floci/aws/services/lambda/launcher/WorkingDirectoryAccessDockerIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/lambda/launcher/WorkingDirectoryAccessDockerIntegrationTest.java @@ -7,10 +7,12 @@ import io.floci.aws.config.EmulatorConfig; import io.floci.aws.core.common.docker.DockerBuildContext; import io.floci.aws.core.common.docker.DockerClientProducer; import io.floci.aws.testing.DockerAvailability; +import io.floci.aws.testing.ParallelLocks; import io.floci.aws.testing.TestImages; import io.smallrye.config.SmallRyeConfigBuilder; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.ResourceLock; import java.io.ByteArrayInputStream; import java.nio.charset.StandardCharsets; @@ -23,6 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; /** Reads the working directory's permissions from a created, unstarted container of a real image. */ +@ResourceLock(ParallelLocks.CONFIG_MAPPING) class WorkingDirectoryAccessDockerIntegrationTest { private static final String DOCKERFILE = """ diff --git a/src/test/java/io/floci/aws/services/route53/Route53NameserverConfigTest.java b/src/test/java/io/floci/aws/services/route53/Route53NameserverConfigTest.java index e0df908ef7..1132e129c7 100644 --- a/src/test/java/io/floci/aws/services/route53/Route53NameserverConfigTest.java +++ b/src/test/java/io/floci/aws/services/route53/Route53NameserverConfigTest.java @@ -1,15 +1,18 @@ package io.floci.aws.services.route53; import io.floci.aws.config.EmulatorConfig; +import io.floci.aws.testing.ParallelLocks; import io.smallrye.config.EnvConfigSource; import io.smallrye.config.SmallRyeConfigBuilder; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.ResourceLock; import java.util.Map; import java.util.Optional; import static org.junit.jupiter.api.Assertions.assertEquals; +@ResourceLock(ParallelLocks.CONFIG_MAPPING) class Route53NameserverConfigTest { @Test void explicitDefaultLiteralIsDistinctFromAnUnsetNameserver() { diff --git a/src/test/java/io/floci/aws/testing/ParallelLocks.java b/src/test/java/io/floci/aws/testing/ParallelLocks.java index d0ce76687e..e47f34c7ec 100644 --- a/src/test/java/io/floci/aws/testing/ParallelLocks.java +++ b/src/test/java/io/floci/aws/testing/ParallelLocks.java @@ -22,6 +22,14 @@ public final class ParallelLocks { */ public static final String PORTS = "floci-local-ports"; + /** + * SmallRye's generation of the {@code EmulatorConfig} mapping classes, which it defines the first time a + * {@code SmallRyeConfigBuilder} builds that mapping. Two classes building it at once fail with + * {@code NoClassDefFoundError} for a nested group's generated class. {@code ParallelLocksInventoryTest} + * checks every plain class that builds it declares this lock. + */ + public static final String CONFIG_MAPPING = "floci-config-mapping"; + private ParallelLocks() { } } diff --git a/src/test/java/io/floci/aws/testing/ParallelLocksInventoryTest.java b/src/test/java/io/floci/aws/testing/ParallelLocksInventoryTest.java index 78022ca773..1df846913a 100644 --- a/src/test/java/io/floci/aws/testing/ParallelLocksInventoryTest.java +++ b/src/test/java/io/floci/aws/testing/ParallelLocksInventoryTest.java @@ -22,7 +22,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; * declares {@link ParallelLocks#PORTS}, so a class that releases a port and binds or dials it later never runs beside one * the kernel could hand that port to. A class opens a socket when its source names one of the socket APIs below, or * names, or extends, another src/test/java class that does (a helper such as {@link LocalHttpsServer}); a class - * this misses fails here instead of flaking in a shard. + * this misses fails here instead of flaking in a shard. A plain class that builds the {@code EmulatorConfig} + * mapping with a {@code SmallRyeConfigBuilder} declares {@link ParallelLocks#CONFIG_MAPPING} the same way. */ class ParallelLocksInventoryTest { @@ -38,6 +39,9 @@ class ParallelLocksInventoryTest { SOCKET_APIS + "|localhost:[0-9]{4}|127\\.0\\.0\\.1:[0-9]{4}|getLocalPort"); private static final Pattern PORTS_LOCK = Pattern.compile( "@ResourceLock\\(\\s*(?:value\\s*=\\s*)?ParallelLocks\\.PORTS\\b"); + private static final Pattern BUILDS_THE_CONFIG_MAPPING = Pattern.compile("withMapping\\(\\s*EmulatorConfig\\.class"); + private static final Pattern CONFIG_MAPPING_LOCK = Pattern.compile( + "@ResourceLock\\(\\s*(?:value\\s*=\\s*)?ParallelLocks\\.CONFIG_MAPPING\\b"); @Test void everyPlainClassThatOpensASocketDeclaresThePortsLock() { @@ -55,6 +59,20 @@ class ParallelLocksInventoryTest { + "ResourceAccessMode.READ otherwise."); } + @Test + void everyPlainClassThatBuildsTheConfigMappingDeclaresItsLock() { + Map sources = sources(); + Set missing = new TreeSet<>(); + sources.forEach((name, source) -> { + if (isTestClass(name) && BUILDS_THE_CONFIG_MAPPING.matcher(source).find() + && !isQuarkus(name, sources, new TreeSet<>()) && !CONFIG_MAPPING_LOCK.matcher(source).find()) { + missing.add(name); + } + }); + assertTrue(missing.isEmpty(), "Plain test classes that build the EmulatorConfig mapping without " + + "@ResourceLock(ParallelLocks.CONFIG_MAPPING): " + missing); + } + /** * The classes whose source names a socket API, and the test classes that name, or extend, a helper whose source * calls one: one hop, because a fixture that only names an address (a {@code localhost:4566} endpoint) would