Skip to content

Commit d6dd041

Browse files
authored
Limit default allocated processors for the test cluster (#133633) (#135910)
This is to ensure consistent test execution. It also supports clusters before 7.6 where the setting key was `processors` instead of `node.processors`
1 parent 8c0bd7f commit d6dd041

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/InternalTestClustersPlugin.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111

1212
import org.elasticsearch.gradle.VersionProperties;
1313
import org.elasticsearch.gradle.internal.info.GlobalBuildInfoPlugin;
14-
import org.elasticsearch.gradle.testclusters.ElasticsearchCluster;
1514
import org.elasticsearch.gradle.testclusters.TestClustersPlugin;
16-
import org.gradle.api.NamedDomainObjectContainer;
1715
import org.gradle.api.Plugin;
1816
import org.gradle.api.Project;
1917

@@ -33,17 +31,5 @@ public void apply(Project project) {
3331
version -> (version.equals(VersionProperties.getElasticsearchVersion()) && buildParams.getSnapshotBuild() == false)
3432
|| buildParams.getBwcVersions().unreleasedInfo(version) == null
3533
);
36-
37-
NamedDomainObjectContainer<ElasticsearchCluster> testClusters = (NamedDomainObjectContainer<ElasticsearchCluster>) project
38-
.getExtensions()
39-
.getByName(TestClustersPlugin.EXTENSION_NAME);
40-
// Limit the number of allocated processors for all nodes to 2 in the cluster by default.
41-
// This is to ensure that the tests run consistently across different environments.
42-
String processorCount = shouldConfigureTestClustersWithOneProcessor() ? "1" : "2";
43-
testClusters.configureEach(elasticsearchCluster -> elasticsearchCluster.setting("node.processors", processorCount));
44-
}
45-
46-
private boolean shouldConfigureTestClustersWithOneProcessor() {
47-
return Boolean.parseBoolean(System.getProperty("tests.configure_test_clusters_with_one_processor", "false"));
4834
}
4935
}

build-tools/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,15 @@ private void createConfiguration() {
14061406
baseConfig.put("cluster.service.slow_master_task_logging_threshold", "5s");
14071407
}
14081408

1409+
// Limit the number of allocated processors for all nodes in the cluster by default.
1410+
// This is to ensure that the tests run consistently across different environments.
1411+
String processorCount = shouldConfigureTestClustersWithOneProcessor() ? "1" : "2";
1412+
if (getVersion().onOrAfter("7.6.0")) {
1413+
baseConfig.put("node.processors", processorCount);
1414+
} else {
1415+
baseConfig.put("processors", processorCount);
1416+
}
1417+
14091418
baseConfig.put("action.destructive_requires_name", "false");
14101419

14111420
HashSet<String> overriden = new HashSet<>(baseConfig.keySet());
@@ -1791,4 +1800,8 @@ private static class LinkCreationException extends UncheckedIOException {
17911800
super(message, cause);
17921801
}
17931802
}
1803+
1804+
private boolean shouldConfigureTestClustersWithOneProcessor() {
1805+
return Boolean.parseBoolean(System.getProperty("tests.configure_test_clusters_with_one_processor", "false"));
1806+
}
17941807
}

test/test-clusters/src/main/java/org/elasticsearch/test/cluster/local/DefaultSettingsProvider.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ public Map<String, String> get(LocalNodeSpec nodeSpec) {
4444

4545
// Limit the number of allocated processors for all nodes in the cluster by default.
4646
// This is to ensure that the tests run consistently across different environments.
47-
settings.put("node.processors", "2");
47+
if (nodeSpec.getVersion().onOrAfter("7.6.0")) {
48+
settings.put("node.processors", "2");
49+
} else {
50+
settings.put("processors", "2");
51+
}
4852

4953
// Default the watermarks to absurdly low to prevent the tests from failing on nodes without enough disk space
5054
settings.put("cluster.routing.allocation.disk.watermark.low", "1b");

0 commit comments

Comments
 (0)