mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-11-30 00:56:50 +00:00
Better reuse heavy test resources
This commit is contained in:
1 parent
bcf3658557
commit
8f78fdf58b
2 files changed
+25
-10
No files matched your search
+16
-3
@@ -14,7 +14,6 @@ import io.dropwizard.core.Configuration;
|
||||
import io.dropwizard.core.setup.Environment;
|
||||
import io.dropwizard.testing.DropwizardTestSupport;
|
||||
import io.dropwizard.testing.junit5.DropwizardAppExtension;
|
||||
import io.dropwizard.testing.junit5.DropwizardExtensionsSupport;
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.grpc.Server;
|
||||
import io.grpc.Status;
|
||||
@@ -29,11 +28,13 @@ import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.signal.chat.rpc.EchoRequest;
|
||||
import org.signal.chat.rpc.EchoServiceGrpc;
|
||||
import org.whispersystems.textsecuregcm.grpc.EchoServiceImpl;
|
||||
@@ -42,7 +43,6 @@ import org.whispersystems.textsecuregcm.grpc.MockRequestAttributesInterceptor;
|
||||
import org.whispersystems.textsecuregcm.grpc.RequestAttributes;
|
||||
import org.whispersystems.textsecuregcm.util.InetAddressRange;
|
||||
|
||||
@ExtendWith(DropwizardExtensionsSupport.class)
|
||||
class ExternalRequestFilterTest {
|
||||
|
||||
@Nested
|
||||
@@ -118,11 +118,24 @@ class ExternalRequestFilterTest {
|
||||
private ManagedChannel channel;
|
||||
|
||||
@Nested
|
||||
// The DropwizardAppExtension is heavy, but the field can't be static because it uses `abstract` methods. Instead,
|
||||
// use PER_CLASS and manage its lifecycle manually, rather than with `DropwizardExtensionSupport`.
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class Http {
|
||||
|
||||
private final DropwizardAppExtension<TestConfiguration> DROPWIZARD_APP_EXTENSION =
|
||||
new DropwizardAppExtension<>(getTestSupport());
|
||||
|
||||
@BeforeAll
|
||||
void setUp() throws Exception {
|
||||
DROPWIZARD_APP_EXTENSION.before();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
void tearDown() {
|
||||
DROPWIZARD_APP_EXTENSION.after();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRestricted() {
|
||||
Client client = DROPWIZARD_APP_EXTENSION.client();
|
||||
|
||||
+9
-7
@@ -5,16 +5,14 @@
|
||||
|
||||
package org.whispersystems.textsecuregcm.storage;
|
||||
|
||||
import static org.testcontainers.containers.localstack.LocalStackContainer.Service.S3;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.jupiter.api.extension.AfterAllCallback;
|
||||
import org.junit.jupiter.api.extension.AfterEachCallback;
|
||||
import org.junit.jupiter.api.extension.BeforeAllCallback;
|
||||
import org.junit.jupiter.api.extension.BeforeEachCallback;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
import org.testcontainers.containers.localstack.LocalStackContainer;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
import org.testcontainers.localstack.LocalStackContainer;
|
||||
import org.testcontainers.utility.DockerImageName;
|
||||
import org.whispersystems.textsecuregcm.util.TestcontainersImages;
|
||||
import reactor.core.publisher.Flux;
|
||||
@@ -40,7 +38,7 @@ public class S3LocalStackExtension implements BeforeEachCallback, AfterEachCallb
|
||||
StringUtils.substringBefore(TestcontainersImages.getLocalStack(), "@"),
|
||||
":"));
|
||||
|
||||
private static LocalStackContainer LOCAL_STACK = new LocalStackContainer(LOCAL_STACK_IMAGE).withServices(S3)
|
||||
private static final LocalStackContainer LOCAL_STACK = new LocalStackContainer(LOCAL_STACK_IMAGE).withServices("s3")
|
||||
.withExposedPorts(4566);
|
||||
|
||||
private final String bucketName;
|
||||
@@ -76,14 +74,18 @@ public class S3LocalStackExtension implements BeforeEachCallback, AfterEachCallb
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterAll(final ExtensionContext context) throws Exception {
|
||||
public void afterAll(final ExtensionContext context) {
|
||||
s3Client.close();
|
||||
LOCAL_STACK.close();
|
||||
// Testcontainers adds a JVM shutdown hook to shut down any running containers, and the running container can be
|
||||
// reused across tests
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeAll(final ExtensionContext context) throws Exception {
|
||||
LOCAL_STACK.start();
|
||||
if (!LOCAL_STACK.isRunning()) {
|
||||
LOCAL_STACK.start();
|
||||
}
|
||||
|
||||
s3Client = S3AsyncClient.builder()
|
||||
.endpointOverride(LOCAL_STACK.getEndpoint())
|
||||
.credentialsProvider(StaticCredentialsProvider
|
||||
|
||||
Reference in new issue
Block a user