Skip to content

Commit

Permalink
Re-throw ResponseException as AssertionError in BasicLicenseUpgradeIT
Browse files Browse the repository at this point in the history
It's possible that in a slow machine the cluster state updates
take a while to be applied, the license information is published
with NORMAL priority, meaning that it can take a while for the
License information to become available. This can lead to race
conditions. In order to wait until the license information is
available, the tests use assertBusy, but assertBusy only retries
if an AssertionException is raised, for that reason we use the
ignore parameter in the http client and later check that the
response was correct, meaning that the check can be retried
if the license information is not ready yet.

Closes elastic#64578
Backport of elastic#67182
  • Loading branch information
fcofdez committed Jan 8, 2021
1 parent 6e4bc37 commit b6c10bd
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ public void testNewClusterHasActiveNonExpiringBasic() throws Exception {

@SuppressWarnings("unchecked")
private void checkBasicLicense() throws Exception {
Response licenseResponse = client().performRequest(new Request("GET", "/_license"));
final Request request = new Request("GET", "/_license");
// This avoids throwing a ResponseException when the license is not ready yet
// allowing to retry the check using assertBusy
request.addParameter("ignore", "404");
Response licenseResponse = client().performRequest(request);
assertOK(licenseResponse);
Map<String, Object> licenseResponseMap = entityAsMap(licenseResponse);
Map<String, Object> licenseMap = (Map<String, Object>) licenseResponseMap.get("license");
assertEquals("basic", licenseMap.get("type"));
Expand All @@ -33,7 +38,12 @@ private void checkBasicLicense() throws Exception {

@SuppressWarnings("unchecked")
private void checkNonExpiringBasicLicense() throws Exception {
Response licenseResponse = client().performRequest(new Request("GET", "/_license"));
final Request request = new Request("GET", "/_license");
// This avoids throwing a ResponseException when the license is not ready yet
// allowing to retry the check using assertBusy
request.addParameter("ignore", "404");
Response licenseResponse = client().performRequest(request);
assertOK(licenseResponse);
Map<String, Object> licenseResponseMap = entityAsMap(licenseResponse);
Map<String, Object> licenseMap = (Map<String, Object>) licenseResponseMap.get("license");
assertEquals("basic", licenseMap.get("type"));
Expand Down

0 comments on commit b6c10bd

Please sign in to comment.