diff --git a/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/it/runner/registry/TestBench.java b/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/it/runner/registry/TestBench.java index 4d9340762093..964c0c5cb020 100644 --- a/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/it/runner/registry/TestBench.java +++ b/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/it/runner/registry/TestBench.java @@ -262,7 +262,7 @@ public void start() { dockerImage, "gunicorn", "--bind=0.0.0.0:9000", - "--worker-class=sync", + "--worker-class=gthread", "--threads=10", "--access-logfile=-", "--keep-alive=0", @@ -401,6 +401,16 @@ private void dumpServerLog(String prefix, File out) throws IOException { } } + private static int findFreePort() { + try (java.net.ServerSocket socket = new java.net.ServerSocket()) { + socket.setReuseAddress(true); + socket.bind(new java.net.InetSocketAddress("127.0.0.1", 0)); + return socket.getLocalPort(); + } catch (java.io.IOException e) { + throw new RuntimeException("Failed to find a free port", e); + } + } + static Builder newBuilder() { return new Builder(); } @@ -442,8 +452,8 @@ public String toString() { } static final class Builder { - private static final String DEFAULT_BASE_URI = "http://localhost:9000"; - private static final String DEFAULT_GRPC_BASE_URI = "http://localhost:9005"; + private static final String DEFAULT_BASE_URI = "http://localhost"; + private static final String DEFAULT_GRPC_BASE_URI = "http://localhost"; private static final String DEFAULT_IMAGE_NAME; private static final String DEFAULT_IMAGE_TAG; @@ -497,11 +507,11 @@ static final class Builder { private Builder() { this( false, - DEFAULT_BASE_URI, - DEFAULT_GRPC_BASE_URI, + DEFAULT_BASE_URI + ":" + findFreePort(), + DEFAULT_GRPC_BASE_URI + ":" + findFreePort(), DEFAULT_IMAGE_NAME, DEFAULT_IMAGE_TAG, - DEFAULT_CONTAINER_NAME); + DEFAULT_CONTAINER_NAME + "_" + java.util.UUID.randomUUID().toString().substring(0, 8)); } private Builder(