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

Use ephemeral ports in integration tests #1780

Merged
merged 3 commits into from
Nov 13, 2023

Conversation

piotrrzysko
Copy link
Member

No description provided.

Copy link
Contributor

@druminski druminski left a comment

Choose a reason for hiding this comment

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

+1 but please take a look at my comment related to reflection

@VisibleForTesting
@SuppressWarnings("unchecked")
public int getPort() {
Field channelsField = FieldUtils.getDeclaredField(Undertow.class, "channels", true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to use reflection to read Undertow port? According to a thread on Stackoverflow something like this should work:

InetSocketAddress socketAddress = (InetSocketAddress) undertow.getListenerInfo().stream().findFirst().orElseThrow(() -> new IllegalStateException("No port available yet.")).getAddress();
return socketAddress.getPort();

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. I applied your suggestion. Thanks.

@@ -151,4 +159,23 @@ private HttpHandler handlers() {
private boolean isFrontendRequestDumperEnabled() {
return hermesServerParameters.isRequestDumperEnabled();
}

@VisibleForTesting
Copy link
Member

Choose a reason for hiding this comment

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

If I understand correctly, this annotation makes the method visible in tests. So do we need this annotation when the method is public, or do we need the public access modifier?

Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand correctly, this annotation makes the method visible in tests.

Nope, this annotation is from Guava and doesn't change anything, it only states that the method was created only for tests. But your question is still valid whether we need it or not. When comes to me, it's ok to use it as it states explicite that the method was created only for test purposes and maybe you shouldn't use it in production.

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't need it. I added it just to emphasize the purpose of this method. After reconsideration, I removed it to avoid causing confusion, as we don't follow a convention of marking methods that way.

@piotrrzysko piotrrzysko merged commit 024b170 into integration_tests_framework Nov 13, 2023
5 of 6 checks passed
@piotrrzysko piotrrzysko deleted the ephemeral_ports_in_it branch November 13, 2023 16:41
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.

None yet

4 participants