Skip to content

Commit

Permalink
Merge pull request #343 from Aiven-Open/anatolii/flaky-test-fix
Browse files Browse the repository at this point in the history
Flaky integration tests fix
  • Loading branch information
aindriu-aiven authored Nov 14, 2024
2 parents 2f52d20 + 489bdc9 commit 8e9e130
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main_push_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ jobs:
run: ./gradlew build test
- name: Build in Linux
if: runner.os == 'Linux'
run: ./gradlew build check test integrationTest
run: ./gradlew build check test integrationTest -i
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.nio.file.Path;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -116,9 +117,16 @@ static LocalStackContainer createS3Container() {
.withServices(LocalStackContainer.Service.S3);
}

static int getRandomPort() throws IOException {
try (ServerSocket socket = new ServerSocket(0)) {
return socket.getLocalPort();
/**
* Finds 2 simultaneously free port for Kafka listeners
*
* @return list of 2 ports
* @throws IOException
* when port allocation failure happens
*/
static List<Integer> getKafkaListenerPorts() throws IOException {
try (ServerSocket socket = new ServerSocket(0); ServerSocket socket2 = new ServerSocket(0)) {
return Arrays.asList(socket.getLocalPort(), socket2.getLocalPort());
} catch (IOException e) {
throw new IOException("Failed to allocate port for test", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ void setUp(final TestInfo testInfo) throws Exception {
testBucketAccessor.createBucket();

connectRunner = new ConnectRunner(OFFSET_FLUSH_INTERVAL_MS);
final int localListenerPort = IntegrationBase.getRandomPort();
final int containerListenerPort = IntegrationBase.getRandomPort();
final List<Integer> ports = IntegrationBase.getKafkaListenerPorts();
final int localListenerPort = ports.get(0);
final int containerListenerPort = ports.get(1);
connectRunner.startConnectCluster(CONNECTOR_NAME, localListenerPort, containerListenerPort);

adminClient = newAdminClient(connectRunner.getBootstrapServers());
Expand Down

0 comments on commit 8e9e130

Please sign in to comment.