mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
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.
This commit is contained in:
1 parent
c24686a17d
commit
67a619d58e
11 files changed
+51
-3
No files matched your search
@@ -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
|
||||
|
||||
+3
@@ -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);
|
||||
|
||||
+3
@@ -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";
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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
|
||||
|
||||
+3
@@ -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 = """
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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() {
|
||||
}
|
||||
}
|
||||
@@ -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<String, String> sources = sources();
|
||||
Set<String> 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
|
||||
|
||||
Reference in new issue
Block a user