Skip to content

Commit e1af32d

Browse files
authored
Adjust gradle base port by one (#58368)
When assigning ports for internal cluster tests, we use the gradle worker id as an adjustment on the base port of 10300. In order to not go outside the max port range, we modulo the worker id by 223. Since gradle worker ids start at 1, we expect to never actually get the base port of 10300. However, as the gradle daemon lasts for longer, the module can result in a value of 0, which cases the test to fail. This commit adjusts the modulo to ensure the value is never 0. closes #58279
1 parent 7c839ee commit e1af32d

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,8 +1409,17 @@ protected static int getBasePort() {
14091409
// Ephemeral ports on Linux start at 32768 so we modulo to make sure that we don't exceed that.
14101410
// This is safe as long as we have fewer than 224 Gradle workers running in parallel
14111411
// See also: https://github.com/elastic/elasticsearch/issues/44134
1412-
final String workerId = System.getProperty(ESTestCase.TEST_WORKER_SYS_PROPERTY);
1413-
final int startAt = workerId == null ? 0 : Math.floorMod(Long.valueOf(workerId), 223);
1412+
final String workerIdStr = System.getProperty(ESTestCase.TEST_WORKER_SYS_PROPERTY);
1413+
final int startAt;
1414+
if (workerIdStr == null) {
1415+
startAt = 0; // IDE
1416+
} else {
1417+
// we adjust the gradle worker id with mod so as to not go over the ephemoral port ranges, but gradle continually
1418+
// increases this value, so the mod can eventually become zero, thus we shift on both sides by 1
1419+
final long workerId = Long.valueOf(workerIdStr);
1420+
assert workerId >= 1 : "Non positive gradle worker id: " + workerIdStr;
1421+
startAt = Math.floorMod(workerId - 1, 223) + 1;
1422+
}
14141423
assert startAt >= 0 : "Unexpected test worker Id, resulting port range would be negative";
14151424
return 10300 + (startAt * 100);
14161425
}

test/framework/src/test/java/org/elasticsearch/test/test/ESTestCaseTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ public void testWorkerSystemProperty() {
189189
assertThat(ESTestCase.TEST_WORKER_VM_ID, not(equals(ESTestCase.DEFAULT_TEST_WORKER_ID)));
190190
}
191191

192-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/58279")
193192
public void testBasePortGradle() {
194193
assumeTrue("requires running tests with Gradle", System.getProperty("tests.gradle") != null);
195194
// Gradle worker IDs are 1 based

0 commit comments

Comments
 (0)