Skip to content

Commit f80e763

Browse files
committed
management.server.port should be 0 when local.server.port has
the same value and `management.server.port` has been defined in the different PropertySource gh-16102
1 parent ce9626d commit f80e763

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/SpringBootTestRandomPortEnvironmentPostProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void postProcessEnvironment(ConfigurableEnvironment environment,
5757
}
5858
Integer serverPort = getPropertyAsInteger(environment, SERVER_PORT_PROPERTY,
5959
8080);
60-
if (!managementPort.equals(serverPort)) {
60+
if (!managementPort.equals(serverPort) || managementPort == 0) {
6161
source.getSource().put(MANAGEMENT_PORT_PROPERTY, "0");
6262
}
6363
else {

spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/SpringBootTestRandomPortEnvironmentPostProcessorTests.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -58,6 +58,17 @@ public void postProcessWhenServerAndManagementPortIsZeroInTestPropertySource() {
5858
assertThat(this.environment.getProperty("management.server.port")).isEqualTo("0");
5959
}
6060

61+
@Test
62+
public void postProcessWhenServerPortAndManagementPortIsZeroInDifferentPropertySources() {
63+
addTestPropertySource("0", null);
64+
Map<String, Object> source = new HashMap<>();
65+
source.put("management.server.port", "0");
66+
this.propertySources.addLast(new MapPropertySource("other", source));
67+
this.postProcessor.postProcessEnvironment(this.environment, null);
68+
assertThat(this.environment.getProperty("server.port")).isEqualTo("0");
69+
assertThat(this.environment.getProperty("management.server.port")).isEqualTo("0");
70+
}
71+
6172
@Test
6273
public void postProcessWhenTestServerAndTestManagementPortAreNonZero() {
6374
addTestPropertySource("8080", "8081");

0 commit comments

Comments
 (0)