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

Random management.server.port gets set to the same value as local.server.port #16102

Closed
gkonupek opened this issue Mar 5, 2019 · 2 comments
Closed
Labels
status: superseded An issue that has been superseded by another type: bug A general bug

Comments

@gkonupek
Copy link

gkonupek commented Mar 5, 2019

A minimum project to reproduce this issue is available here: https://github.com/gkonupek/SpringBootActuatorIssue

The project is a basic Spring Boot web application with Actuator. A problem occurs in tests when using Spring Boot version 2.1.x. In this case, I'm using version 2.1.3.RELEASE.

In the mentioned project, on branch "master" there is the following situation:

  • DemoApplicationTests I'm using @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) annotation to run the application on a random, free port.
  • In application.properties file, I've specified management.server.port=0 to make Actuator endpoint run on a random, free port as well.
  • Furthermore, in DemoApplicationTests:
    • I'm injecting 2 values: serverPort (annotated with @LocalServerPort) and managementPort (annotated with @LocalManagementPort).
    • I've created a simple JUnit 5 test in which I'm checking, that both mentioned ports have a different value (that's my expectation).
    • Notice, that the test is also annotated with @ActiveProfiles("test") - it will be important later.
  • The Spring Boot version used in this case is 2.0.5.RELEASE.

In this configuration I expect the test to pass. Indeed, the generated ports are different.

Spring Boot 2.1.x

Now, in the repository there is a second branch named "spring-boot-2.1.x". The only difference between master is that the Spring Boot version has been upgraded to 2.1.3.RELEASE.

Unfortunately, in this configuration the test is failing. Both serverPort and managementPort have the same value.

Role of @ActiveProfiles annotation?

Another interesting case is present on the branch named "without-active-profile". In this case, the Spring Boot version is still 2.1.3.RELEASE. However, I've removed the @ActiveProfiles("test") annotation from DemoApplicationTests. In this case, the test is passing again - the port numbers are different.

The last scenario is actually the workaround, which I've applied to make my application work. Instead of using the annotation I could just import my application-test.properties file manually, by using @TestPropertySource annotation. However, I'd really love to see this issue explained and eventually fixed.

Cheers,
Grzegorz

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 5, 2019
@wilkinsona
Copy link
Member

wilkinsona commented Mar 5, 2019

This sounds like it may be a bug in SpringBootTestRandomPortEnvironmentPostProcessor that was introduced in 2.1 to fix #4424.

@mbhave mbhave added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 6, 2019
@mbhave mbhave added this to the 2.1.x milestone Mar 6, 2019
nosan added a commit to nosan/spring-boot that referenced this issue Mar 6, 2019
the same value and `management.server.port` has been defined
in the different PropertySource

spring-projectsgh-16102
nosan added a commit to nosan/spring-boot that referenced this issue Mar 6, 2019
the same value and `management.server.port` has been defined
in the different PropertySource

spring-projectsgh-16102
@mbhave
Copy link
Contributor

mbhave commented Mar 8, 2019

Closing in favor of PR #16108.

@mbhave mbhave closed this as completed Mar 8, 2019
@mbhave mbhave removed this from the 2.1.x milestone Mar 8, 2019
@mbhave mbhave added the status: superseded An issue that has been superseded by another label Mar 8, 2019
nosan added a commit to nosan/spring-boot that referenced this issue Mar 8, 2019
the same value and `management.server.port` has been defined
in the different PropertySource

spring-projectsgh-16102
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded An issue that has been superseded by another type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants