From b29d7e8e4dccd80bd9132e046e805f28d251926d Mon Sep 17 00:00:00 2001 From: Simon Schrottner Date: Mon, 14 Jul 2025 07:56:05 +0200 Subject: [PATCH] test(flagd): Reduce flakiness of ChannelConnectorTest by using random port The ChannelConnectorTests was flacky on github actions, as it used 8080 all the time for its test. With this change we will use a random port for each test run. Signed-off-by: Simon Schrottner --- .../flagd/resolver/common/ChannelConnectorTest.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/resolver/common/ChannelConnectorTest.java b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/resolver/common/ChannelConnectorTest.java index dad49155b..ed97f971c 100644 --- a/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/resolver/common/ChannelConnectorTest.java +++ b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/resolver/common/ChannelConnectorTest.java @@ -21,6 +21,7 @@ import io.grpc.netty.NettyServerBuilder; import io.grpc.stub.StreamObserver; import java.io.IOException; +import java.net.ServerSocket; import java.util.ArrayList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -57,12 +58,16 @@ void setUp() throws Exception { } private void setupTestGrpcServer() throws IOException { + var testSocket = new ServerSocket(0); + var port = testSocket.getLocalPort(); + testSocket.close(); + testServer = - NettyServerBuilder.forPort(8080).addService(testServiceImpl).build(); + NettyServerBuilder.forPort(port).addService(testServiceImpl).build(); testServer.start(); if (testChannel == null) { - testChannel = ManagedChannelBuilder.forAddress("localhost", 8080) + testChannel = ManagedChannelBuilder.forAddress("localhost", port) .usePlaintext() .build(); }