From 4541521e61855ce6a9df1fad7d08ee24b893a674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mariusz=20J=C3=B3zala?= <377355+jozala@users.noreply.github.com> Date: Fri, 3 Oct 2025 14:26:13 +0200 Subject: [PATCH] Limit default allocated processors for the test cluster (#133633) This is to ensure consistent test execution. It also supports clusters before 7.6 where the setting key was `processors` instead of `node.processors` --- .../internal/InternalTestClustersPlugin.java | 14 -------------- .../gradle/testclusters/ElasticsearchNode.java | 13 +++++++++++++ .../cluster/local/DefaultSettingsProvider.java | 6 +++++- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/InternalTestClustersPlugin.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/InternalTestClustersPlugin.java index 2a2e1ea28d1ec..d23ad9a9e9b7b 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/InternalTestClustersPlugin.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/InternalTestClustersPlugin.java @@ -11,9 +11,7 @@ import org.elasticsearch.gradle.VersionProperties; import org.elasticsearch.gradle.internal.info.GlobalBuildInfoPlugin; -import org.elasticsearch.gradle.testclusters.ElasticsearchCluster; import org.elasticsearch.gradle.testclusters.TestClustersPlugin; -import org.gradle.api.NamedDomainObjectContainer; import org.gradle.api.Plugin; import org.gradle.api.Project; @@ -33,17 +31,5 @@ public void apply(Project project) { version -> (version.equals(VersionProperties.getElasticsearchVersion()) && buildParams.getSnapshotBuild() == false) || buildParams.getBwcVersions().unreleasedInfo(version) == null ); - - NamedDomainObjectContainer testClusters = (NamedDomainObjectContainer) project - .getExtensions() - .getByName(TestClustersPlugin.EXTENSION_NAME); - // Limit the number of allocated processors for all nodes to 2 in the cluster by default. - // This is to ensure that the tests run consistently across different environments. - String processorCount = shouldConfigureTestClustersWithOneProcessor() ? "1" : "2"; - testClusters.configureEach(elasticsearchCluster -> elasticsearchCluster.setting("node.processors", processorCount)); - } - - private boolean shouldConfigureTestClustersWithOneProcessor() { - return Boolean.parseBoolean(System.getProperty("tests.configure_test_clusters_with_one_processor", "false")); } } diff --git a/build-tools/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java b/build-tools/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java index e46fabac3efd1..81448dc1136e4 100644 --- a/build-tools/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java +++ b/build-tools/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java @@ -1406,6 +1406,15 @@ private void createConfiguration() { baseConfig.put("cluster.service.slow_master_task_logging_threshold", "5s"); } + // Limit the number of allocated processors for all nodes in the cluster by default. + // This is to ensure that the tests run consistently across different environments. + String processorCount = shouldConfigureTestClustersWithOneProcessor() ? "1" : "2"; + if (getVersion().onOrAfter("7.6.0")) { + baseConfig.put("node.processors", processorCount); + } else { + baseConfig.put("processors", processorCount); + } + baseConfig.put("action.destructive_requires_name", "false"); HashSet overriden = new HashSet<>(baseConfig.keySet()); @@ -1791,4 +1800,8 @@ private static class LinkCreationException extends UncheckedIOException { super(message, cause); } } + + private boolean shouldConfigureTestClustersWithOneProcessor() { + return Boolean.parseBoolean(System.getProperty("tests.configure_test_clusters_with_one_processor", "false")); + } } diff --git a/test/test-clusters/src/main/java/org/elasticsearch/test/cluster/local/DefaultSettingsProvider.java b/test/test-clusters/src/main/java/org/elasticsearch/test/cluster/local/DefaultSettingsProvider.java index 2fdf0df41736a..4ea74811abdc3 100644 --- a/test/test-clusters/src/main/java/org/elasticsearch/test/cluster/local/DefaultSettingsProvider.java +++ b/test/test-clusters/src/main/java/org/elasticsearch/test/cluster/local/DefaultSettingsProvider.java @@ -44,7 +44,11 @@ public Map get(LocalNodeSpec nodeSpec) { // Limit the number of allocated processors for all nodes in the cluster by default. // This is to ensure that the tests run consistently across different environments. - settings.put("node.processors", "2"); + if (nodeSpec.getVersion().onOrAfter("7.6.0")) { + settings.put("node.processors", "2"); + } else { + settings.put("processors", "2"); + } // Default the watermarks to absurdly low to prevent the tests from failing on nodes without enough disk space settings.put("cluster.routing.allocation.disk.watermark.low", "1b");