Skip to content

Commit aeb1c82

Browse files
authored
test(flagd): Reduce flakiness of ChannelConnectorTest by using random port (#1513)
Signed-off-by: Simon Schrottner <simon.schrottner@dynatrace.com>
1 parent ec6a829 commit aeb1c82

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/resolver/common/ChannelConnectorTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.grpc.netty.NettyServerBuilder;
2222
import io.grpc.stub.StreamObserver;
2323
import java.io.IOException;
24+
import java.net.ServerSocket;
2425
import java.util.ArrayList;
2526
import java.util.concurrent.CountDownLatch;
2627
import java.util.concurrent.TimeUnit;
@@ -57,12 +58,16 @@ void setUp() throws Exception {
5758
}
5859

5960
private void setupTestGrpcServer() throws IOException {
61+
var testSocket = new ServerSocket(0);
62+
var port = testSocket.getLocalPort();
63+
testSocket.close();
64+
6065
testServer =
61-
NettyServerBuilder.forPort(8080).addService(testServiceImpl).build();
66+
NettyServerBuilder.forPort(port).addService(testServiceImpl).build();
6267
testServer.start();
6368

6469
if (testChannel == null) {
65-
testChannel = ManagedChannelBuilder.forAddress("localhost", 8080)
70+
testChannel = ManagedChannelBuilder.forAddress("localhost", port)
6671
.usePlaintext()
6772
.build();
6873
}

0 commit comments

Comments
 (0)