Skip to content

Commit

Permalink
Fix test framework assert when multiple OS names are found (#68487)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
droberts195 committed Feb 4, 2021
1 parent 30177e4 commit 5987509
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<String> osPrettyNames = new HashSet<>();
SortedSet<String> osPrettyNames = new TreeSet<>();

@SuppressWarnings("unchecked")
final Map<String, Object> nodes = (Map<String, Object>) restTestResponse.evaluate("nodes");
Expand All @@ -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";
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() {
Expand Down

0 comments on commit 5987509

Please sign in to comment.