From 0ae4ad5faf499c286fd36a18addd08e3d03ce548 Mon Sep 17 00:00:00 2001 From: David Roberts Date: Wed, 3 Feb 2021 20:41:49 +0000 Subject: [PATCH] Fix test framework assert when multiple OS names are found Prevent failures of the test framework in mixed version tests when different Java versions report the name of a particular OS version differently. Fixes #68346 --- .../rest/yaml/ESClientYamlSuiteTestCase.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java index 458a1e726a1c1..b349e99d5d86e 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java @@ -51,6 +51,8 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; /** * Runs a suite of yaml tests shared with all the official Elasticsearch @@ -339,7 +341,7 @@ private String readOsFromNodesInfo(RestClient restClient) throws IOException { final Request request = new Request("GET", "/_nodes/os"); Response response = restClient.performRequest(request); ClientYamlTestResponse restTestResponse = new ClientYamlTestResponse(response); - Set osPrettyNames = new HashSet<>(); + SortedSet osPrettyNames = new TreeSet<>(); @SuppressWarnings("unchecked") final Map nodes = (Map) restTestResponse.evaluate("nodes"); @@ -351,8 +353,16 @@ private String readOsFromNodesInfo(RestClient restClient) throws IOException { osPrettyNames.add((String) XContentMapValues.extractValue("os.pretty_name", nodeInfo)); } - assert osPrettyNames.size() == 1 : "mixed os cluster found: " + osPrettyNames; - return osPrettyNames.iterator().next(); + assert osPrettyNames.isEmpty() == false : "no os found"; + + // Although in theory there should only be one element as all nodes are running on the same machine, + // in reality there can be two in mixed version clusters if different Java versions report the OS + // name differently. This has been observed to happen on Windows, where Java needs to be updated to + // recognize new Windows versions, and until this update has been done the newest version of Windows + // is reported as the previous one. In this case taking the last alphabetically is likely to be most + // accurate, for example if "Windows Server 2016" and "Windows Server 2019" are reported by different + // Java versions then Windows Server 2019 is likely to be correct. + return osPrettyNames.last(); } protected RequestOptions getCatNodesVersionMasterRequestOptions() {