Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flaky integration tests fix #343

Merged
merged 1 commit into from
Nov 14, 2024

Conversation

AnatolyPopov
Copy link
Contributor

No description provided.

@AnatolyPopov AnatolyPopov requested review from a team as code owners November 13, 2024 15:49
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this to improve the readout on the build?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly, noticed when the test failed that there were almost no details about failure.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok cool, just wanted to make sure it was on purpose

Copy link
Contributor

@aindriu-aiven aindriu-aiven left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@aindriu-aiven aindriu-aiven left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, sorry looks like I commented instead of approved before.

Comment on lines +129 to 134
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);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this code lead to hard to detect collisions and flaky tests?

Reasoning:
The socket is opened and a port assigned.
We save the port number.
we close the socket as we exit the try. (TIMEOUT LINGER now applies to the port number)
The calling code then uses the port numbers.

If 2 tests are running and the timing is just right. The second test can retrieve the same port number that were retrieved in the first test.

Solution:
Return ServerSocket not port numbers. Then you can get as many sockets as needed and hold them until the code is finished.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reserving a free port for future use is pretty tricky to do: even if you return the ServerSocket, you need to close it before the port is freed and any process on the host machine (including parallel tests) could sneak right in and occupy it.

The right thing to do might be to detect if that specific failure occurred (that the supposedly free port is no longer free) and retry, but I'd take the point of view that change makes the test less flaky than it was for now. The two free ports can no longer be assigned to the same value during the same test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Claudenw AFAIU you are talking about parallel test execution that we are not doing as of now.

Copy link
Contributor

@RyanSkraba RyanSkraba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM -- @Claudenw has a point, but this change leaves the code better than it was.

@aindriu-aiven aindriu-aiven merged commit 8e9e130 into s3-source-release Nov 14, 2024
8 checks passed
@aindriu-aiven aindriu-aiven deleted the anatolii/flaky-test-fix branch November 14, 2024 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants