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
This commit is contained in:
Ryan Ernst 2020-06-23 15:14:59 -07:00 committed by Ryan Ernst
parent 89c03e593c
commit 6285b87b97
No known key found for this signature in database
GPG Key ID: 5F7EA39E15F54DCE
2 changed files with 11 additions and 3 deletions

View File

@ -1430,8 +1430,17 @@ public abstract class ESTestCase extends LuceneTestCase {
// Ephemeral ports on Linux start at 32768 so we modulo to make sure that we don't exceed that. // Ephemeral ports on Linux start at 32768 so we modulo to make sure that we don't exceed that.
// This is safe as long as we have fewer than 224 Gradle workers running in parallel // This is safe as long as we have fewer than 224 Gradle workers running in parallel
// See also: https://github.com/elastic/elasticsearch/issues/44134 // See also: https://github.com/elastic/elasticsearch/issues/44134
final String workerId = System.getProperty(ESTestCase.TEST_WORKER_SYS_PROPERTY); final String workerIdStr = System.getProperty(ESTestCase.TEST_WORKER_SYS_PROPERTY);
final int startAt = workerId == null ? 0 : (int) Math.floorMod(Long.valueOf(workerId), 223); final int startAt;
if (workerIdStr == null) {
startAt = 0; // IDE
} else {
// we adjust the gradle worker id with mod so as to not go over the ephemoral port ranges, but gradle continually
// increases this value, so the mod can eventually become zero, thus we shift on both sides by 1
final long workerId = Long.valueOf(workerIdStr);
assert workerId >= 1 : "Non positive gradle worker id: " + workerIdStr;
startAt = Math.floorMod(workerId - 1, 223) + 1;
}
assert startAt >= 0 : "Unexpected test worker Id, resulting port range would be negative"; assert startAt >= 0 : "Unexpected test worker Id, resulting port range would be negative";
return 10300 + (startAt * 100); return 10300 + (startAt * 100);
} }

View File

@ -189,7 +189,6 @@ public class ESTestCaseTests extends ESTestCase {
assertThat(ESTestCase.TEST_WORKER_VM_ID, not(equals(ESTestCase.DEFAULT_TEST_WORKER_ID))); assertThat(ESTestCase.TEST_WORKER_VM_ID, not(equals(ESTestCase.DEFAULT_TEST_WORKER_ID)));
} }
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/58279")
public void testBasePortGradle() { public void testBasePortGradle() {
assumeTrue("requires running tests with Gradle", System.getProperty("tests.gradle") != null); assumeTrue("requires running tests with Gradle", System.getProperty("tests.gradle") != null);
// Gradle worker IDs are 1 based // Gradle worker IDs are 1 based