Skip to content

Commit

Permalink
[Test] Use larger client ports range for tests running on Windows (#1…
Browse files Browse the repository at this point in the history
…03894)

This PR increases client's port ranges for tests which are executed
on Windows in order to avoid failures due to some port ranges being
excluded from use. The larger ports range (300) is chosen based on
the observation where a random consecutive range of 200 ports can
be excluded on Windows test workers.

Closes #102349
  • Loading branch information
slobodanadamovic committed Jan 4, 2024
1 parent f5f0cd2 commit bdf5c7f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package org.elasticsearch.transport.netty4;

import org.apache.lucene.util.Constants;
import org.elasticsearch.ESNetty4IntegTestCase;
import org.elasticsearch.action.admin.cluster.node.info.NodeInfo;
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
Expand All @@ -31,14 +32,16 @@
@ClusterScope(scope = Scope.SUITE, supportsDedicatedMasters = false, numDataNodes = 1, numClientNodes = 0)
public class Netty4TransportMultiPortIntegrationIT extends ESNetty4IntegTestCase {

private static final int NUMBER_OF_CLIENT_PORTS = Constants.WINDOWS ? 300 : 10;

private static int randomPort = -1;
private static String randomPortRange;

@Override
protected Settings nodeSettings(int nodeOrdinal, Settings otherSettings) {
if (randomPort == -1) {
randomPort = randomIntBetween(49152, 65525);
randomPortRange = Strings.format("%s-%s", randomPort, randomPort + 10);
randomPort = randomIntBetween(49152, 65535 - NUMBER_OF_CLIENT_PORTS);
randomPortRange = Strings.format("%s-%s", randomPort, randomPort + NUMBER_OF_CLIENT_PORTS);
}
Settings.Builder builder = Settings.builder()
.put(super.nodeSettings(nodeOrdinal, otherSettings))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.elasticsearch.xpack.security.authc.pki;

import org.apache.http.nio.conn.ssl.SSLIOSessionStrategy;
import org.apache.lucene.util.Constants;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.Response;
Expand Down Expand Up @@ -34,11 +35,13 @@

public class PkiOptionalClientAuthTests extends SecuritySingleNodeTestCase {

private static final int NUMBER_OF_CLIENT_PORTS = Constants.WINDOWS ? 300 : 100;

private static int randomClientPort;

@BeforeClass
public static void initPort() {
randomClientPort = randomIntBetween(49000, 65500);
randomClientPort = randomIntBetween(49152, 65535 - NUMBER_OF_CLIENT_PORTS);
}

@Override
Expand All @@ -47,7 +50,7 @@ protected boolean addMockHttpTransport() {
}

protected Settings nodeSettings() {
String randomClientPortRange = randomClientPort + "-" + (randomClientPort + 100);
String randomClientPortRange = randomClientPort + "-" + (randomClientPort + NUMBER_OF_CLIENT_PORTS);

Settings.Builder builder = Settings.builder()
.put(super.nodeSettings())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package org.elasticsearch.xpack.security.transport.filter;

import org.apache.lucene.util.Constants;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.core.SuppressForbidden;
Expand All @@ -28,11 +29,14 @@
// no client nodes as they all get rejected on network connections
@ClusterScope(scope = Scope.SUITE, numDataNodes = 0, numClientNodes = 0)
public class IpFilteringIntegrationTests extends SecurityIntegTestCase {

private static final int NUMBER_OF_CLIENT_PORTS = Constants.WINDOWS ? 300 : 100;

private static int randomClientPort;

@BeforeClass
public static void getRandomPort() {
randomClientPort = randomIntBetween(49000, 65500); // ephemeral port
randomClientPort = randomIntBetween(49152, 65535 - NUMBER_OF_CLIENT_PORTS); // ephemeral port
}

@Override
Expand All @@ -42,7 +46,7 @@ protected boolean addMockHttpTransport() {

@Override
protected Settings nodeSettings(int nodeOrdinal, Settings otherSettings) {
String randomClientPortRange = randomClientPort + "-" + (randomClientPort + 100);
String randomClientPortRange = randomClientPort + "-" + (randomClientPort + NUMBER_OF_CLIENT_PORTS);
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal, otherSettings))
.put("transport.profiles.client.port", randomClientPortRange)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package org.elasticsearch.xpack.security.transport.filter;

import org.apache.lucene.util.Constants;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.core.Strings;
Expand All @@ -26,13 +27,15 @@
@ClusterScope(scope = TEST, supportsDedicatedMasters = false, numDataNodes = 1)
public class IpFilteringUpdateTests extends SecurityIntegTestCase {

private static final int NUMBER_OF_CLIENT_PORTS = Constants.WINDOWS ? 300 : 100;

private static int randomClientPort;

private final boolean httpEnabled = randomBoolean();

@BeforeClass
public static void getRandomPort() {
randomClientPort = randomIntBetween(49000, 65500);
randomClientPort = randomIntBetween(49152, 65535 - NUMBER_OF_CLIENT_PORTS);
}

@Override
Expand All @@ -42,7 +45,7 @@ protected boolean addMockHttpTransport() {

@Override
protected Settings nodeSettings(int nodeOrdinal, Settings otherSettings) {
String randomClientPortRange = randomClientPort + "-" + (randomClientPort + 100);
String randomClientPortRange = randomClientPort + "-" + (randomClientPort + NUMBER_OF_CLIENT_PORTS);
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal, otherSettings))
.put("xpack.security.transport.filter.deny", "127.0.0.200")
Expand Down

0 comments on commit bdf5c7f

Please sign in to comment.