Skip to content

Commit 75accd3

Browse files
Dhriti07Dhriti Chopra
andauthored
test(storage): limit integration test forks to 1 and other integration test fixes (googleapis#13400)
After the migration to the mono-repo parent pom defined fork-count for maven failsafe plugin as 1C which runs 1 JVM fork per CPU Core. This could be the reason for multiple issues across various tests due to the parallelism such as thread starvation, CPU throttling, and timeout flakiness on multi-core CI VMs. This PR overrides the parent POM configuration to limit the integration test fork count to 1 in google-cloud-storage. This Pr also contains an attempted fix for vm timeout errors and hangs in the integration test. Rationale: Previously the GCS client and the FakeServer run in the same JVM and share the same Netty thread pool. When the client makes a blocking call and waits for the server, it occupies the shared threads. This could have starved the mock server preventing it from processing the request. Note: The tests will take ~ 5-10 longer to run than previous configuration. --------- Co-authored-by: Dhriti Chopra <dhritichopra@google.com>
1 parent c127538 commit 75accd3

3 files changed

Lines changed: 26 additions & 6 deletions

File tree

java-storage/google-cloud-storage/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,17 @@
460460
</dependency>
461461
</dependencies>
462462
</plugin>
463+
<plugin>
464+
<groupId>org.apache.maven.plugins</groupId>
465+
<artifactId>maven-failsafe-plugin</artifactId>
466+
<configuration>
467+
<forkCount>1</forkCount>
468+
<reuseForks>false</reuseForks>
469+
<systemPropertyVariables>
470+
<logback.statusListenerClass>ch.qos.logback.core.status.NopStatusListener</logback.statusListenerClass>
471+
</systemPropertyVariables>
472+
</configuration>
473+
</plugin>
463474
</plugins>
464475
</build>
465476

java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/FakeServer.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,20 @@
2828
import java.net.InetSocketAddress;
2929
import java.time.Duration;
3030
import java.util.Locale;
31+
import java.util.concurrent.ScheduledThreadPoolExecutor;
3132
import java.util.concurrent.TimeUnit;
3233

3334
final class FakeServer implements AutoCloseable {
3435

3536
private final Server server;
3637
private final GrpcStorageOptions grpcStorageOptions;
38+
private final ScheduledThreadPoolExecutor executor;
3739

38-
FakeServer(Server server, GrpcStorageOptions grpcStorageOptions) {
40+
FakeServer(
41+
Server server, GrpcStorageOptions grpcStorageOptions, ScheduledThreadPoolExecutor executor) {
3942
this.server = server;
4043
this.grpcStorageOptions = grpcStorageOptions;
44+
this.executor = executor;
4145
}
4246

4347
GrpcStorageOptions getGrpcStorageOptions() {
@@ -51,11 +55,16 @@ StorageSettings storageSettings() throws IOException {
5155
@Override
5256
public void close() throws InterruptedException {
5357
server.shutdownNow().awaitTermination(10, TimeUnit.SECONDS);
58+
executor.shutdownNow();
59+
//noinspection ResultOfMethodCallIgnored
60+
executor.awaitTermination(5, TimeUnit.SECONDS);
5461
}
5562

5663
static FakeServer of(StorageGrpc.StorageImplBase service) throws IOException {
57-
InetSocketAddress address = new InetSocketAddress("localhost", 0);
58-
Server server = NettyServerBuilder.forAddress(address).addService(service).build();
64+
InetSocketAddress address = new InetSocketAddress("127.0.0.1", 0);
65+
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(4);
66+
Server server =
67+
NettyServerBuilder.forAddress(address).addService(service).executor(executor).build();
5968
server.start();
6069
String endpoint = String.format(Locale.US, "%s:%d", address.getHostString(), server.getPort());
6170
GrpcStorageOptions grpcStorageOptions =
@@ -80,6 +89,6 @@ static FakeServer of(StorageGrpc.StorageImplBase service) throws IOException {
8089
.setMaxRpcTimeoutDuration(Duration.ofSeconds(25))
8190
.build())
8291
.build();
83-
return new FakeServer(server, grpcStorageOptions);
92+
return new FakeServer(server, grpcStorageOptions, executor);
8493
}
8594
}

java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/it/runner/registry/TestBench.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,8 @@ public String toString() {
442442
}
443443

444444
static final class Builder {
445-
private static final String DEFAULT_BASE_URI = "http://localhost:9000";
446-
private static final String DEFAULT_GRPC_BASE_URI = "http://localhost:9005";
445+
private static final String DEFAULT_BASE_URI = "http://127.0.0.1:9000";
446+
private static final String DEFAULT_GRPC_BASE_URI = "http://127.0.0.1:9005";
447447
private static final String DEFAULT_IMAGE_NAME;
448448
private static final String DEFAULT_IMAGE_TAG;
449449

0 commit comments

Comments
 (0)