Skip to content

Commit afa3dda

Browse files
committed
fix(storage): fix flaky storage integration tests
1 parent d08691a commit afa3dda

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

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

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public void start() {
262262
dockerImage,
263263
"gunicorn",
264264
"--bind=0.0.0.0:9000",
265-
"--worker-class=sync",
265+
"--worker-class=gthread",
266266
"--threads=10",
267267
"--access-logfile=-",
268268
"--keep-alive=0",
@@ -401,6 +401,15 @@ private void dumpServerLog(String prefix, File out) throws IOException {
401401
}
402402
}
403403

404+
private static int findFreePort() {
405+
try (java.net.ServerSocket socket = new java.net.ServerSocket(0)) {
406+
socket.setReuseAddress(true);
407+
return socket.getLocalPort();
408+
} catch (java.io.IOException e) {
409+
throw new RuntimeException("Failed to find a free port", e);
410+
}
411+
}
412+
404413
static Builder newBuilder() {
405414
return new Builder();
406415
}
@@ -495,13 +504,16 @@ static final class Builder {
495504
private String containerName;
496505

497506
private Builder() {
498-
this(
499-
false,
500-
DEFAULT_BASE_URI,
501-
DEFAULT_GRPC_BASE_URI,
502-
DEFAULT_IMAGE_NAME,
503-
DEFAULT_IMAGE_TAG,
504-
DEFAULT_CONTAINER_NAME);
507+
int httpPort = findFreePort();
508+
int grpcPort = findFreePort();
509+
String uuid = java.util.UUID.randomUUID().toString().substring(0, 8);
510+
511+
this.ignorePullError = false;
512+
this.baseUri = "http://127.0.0.1:" + httpPort;
513+
this.gRPCBaseUri = "http://127.0.0.1:" + grpcPort;
514+
this.dockerImageName = DEFAULT_IMAGE_NAME;
515+
this.dockerImageTag = DEFAULT_IMAGE_TAG;
516+
this.containerName = DEFAULT_CONTAINER_NAME + "_" + uuid;
505517
}
506518

507519
private Builder(

0 commit comments

Comments
 (0)