Skip to content

Commit 4602bc8

Browse files
committed
Limit default allocated processors for the test cluster
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 0b70308 commit 4602bc8

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
@@ -1387,6 +1387,15 @@ private void createConfiguration() {
13871387
baseConfig.put("cluster.service.slow_master_task_logging_threshold", "5s");
13881388
}
13891389

1390+
// Limit the number of allocated processors for all nodes in the cluster by default.
1391+
// This is to ensure that the tests run consistently across different environments.
1392+
String processorCount = shouldConfigureTestClustersWithOneProcessor() ? "1" : "2";
1393+
if (getVersion().onOrAfter("7.6.0")) {
1394+
baseConfig.put("node.processors", processorCount);
1395+
} else {
1396+
baseConfig.put("processors", processorCount);
1397+
}
1398+
13901399
baseConfig.put("action.destructive_requires_name", "false");
13911400

13921401
HashSet<String> overriden = new HashSet<>(baseConfig.keySet());
@@ -1772,4 +1781,8 @@ private static class LinkCreationException extends UncheckedIOException {
17721781
super(message, cause);
17731782
}
17741783
}
1784+
1785+
private boolean shouldConfigureTestClustersWithOneProcessor() {
1786+
return Boolean.parseBoolean(System.getProperty("tests.configure_test_clusters_with_one_processor", "false"));
1787+
}
17751788
}

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)