Skip to content

Commit 3c3ea41

Browse files
authored
Fix test allocated processors test (#55429)
This test tries to set the number of allocated processors to seven. That is fine, unless the test is running on a machine where Runtime#availableProcessors is less than seven (typically when there are fewer than seven logical cores, but it can happen in various other ways related to CPU quotas in Docker containers with Docker-aware JVMs, etc.). This commit addresses this by randomizing the number of allocated processors, to a value that is less than or equal to the hard constraint on the number of allocated processors.
1 parent 71a3dc9 commit 3c3ea41

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

server/src/test/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsIT.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,13 @@ public void testValuesSmokeScreen() throws IOException, ExecutionException, Inte
210210
}
211211

212212
public void testAllocatedProcessors() throws Exception {
213-
// start one node with 7 processors.
214-
internalCluster().startNode(Settings.builder().put(EsExecutors.NODE_PROCESSORS_SETTING.getKey(), 7).build());
213+
// the node.processors setting is bounded above by Runtime#availableProcessors
214+
final int nodeProcessors = randomIntBetween(1, Runtime.getRuntime().availableProcessors());
215+
internalCluster().startNode(Settings.builder().put(EsExecutors.NODE_PROCESSORS_SETTING.getKey(), nodeProcessors).build());
215216
waitForNodes(1);
216217

217218
ClusterStatsResponse response = client().admin().cluster().prepareClusterStats().get();
218-
assertThat(response.getNodesStats().getOs().getAllocatedProcessors(), equalTo(7));
219+
assertThat(response.getNodesStats().getOs().getAllocatedProcessors(), equalTo(nodeProcessors));
219220
}
220221

221222
public void testClusterStatusWhenStateNotRecovered() throws Exception {

0 commit comments

Comments
 (0)