Fix get-license test failure by ensure cluster is ready (#60498) (#60569)

When a new cluster starts, the HTTP layer becomes ready to accept incoming 
requests while the basic license is still being populated in the background. 
When a get license request comes in before the license is ready, it can get 
404 error. This PR fixes it by either wrap the license check in assertBusy or 
ensure the license is ready before perform the check.

This is a backport for both #60498 and #60573
This commit is contained in:
Yang Wang 2020-08-03 19:40:03 +10:00 committed by GitHub
parent 3270cb3088
commit a76fc324d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 13 deletions

View File

@ -104,7 +104,7 @@ public class DocsClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
@Before
public void waitForRequirements() throws Exception {
if (isCcrTest()) {
if (isCcrTest() || isGetLicenseTest()) {
ESRestTestCase.waitForActiveLicense(adminClient());
}
}
@ -175,6 +175,11 @@ public class DocsClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
return testName != null && testName.contains("/ccr/");
}
protected boolean isGetLicenseTest() {
String testName = getTestName();
return testName != null && (testName.contains("/get-license/") || testName.contains("\\get-license\\"));
}
/**
* Compares the results of running two analyzers against many random
* strings. The goal is to figure out if two anlayzers are "the same" by

View File

@ -97,10 +97,16 @@ public class EnableSecurityOnBasicLicenseIT extends ESRestTestCase {
return EntityUtils.toString(response.getEntity());
}
private void checkBasicLicenseType() throws IOException {
Map<String, Object> license = getAsMap("/_license");
assertThat(license, notNullValue());
assertThat(ObjectPath.evaluate(license, "license.type"), equalTo("basic"));
private void checkBasicLicenseType() throws Exception {
assertBusy(() -> {
try {
Map<String, Object> license = getAsMap("/_license");
assertThat(license, notNullValue());
assertThat(ObjectPath.evaluate(license, "license.type"), equalTo("basic"));
} catch (ResponseException e) {
throw new AssertionError(e);
}
});
}
private void checkSecurityStatus(boolean expectEnabled) throws IOException {

View File

@ -77,10 +77,16 @@ public class SecurityWithBasicLicenseIT extends SecurityInBasicRestTestCase {
client().performRequest(new Request("POST", "/_license/start_basic?acknowledge=true"));
}
private void checkLicenseType(String type) throws IOException {
Map<String, Object> license = getAsMap("/_license");
assertThat(license, notNullValue());
assertThat(ObjectPath.evaluate(license, "license.type"), equalTo(type));
private void checkLicenseType(String type) throws Exception {
assertBusy(() -> {
try {
Map<String, Object> license = getAsMap("/_license");
assertThat(license, notNullValue());
assertThat(ObjectPath.evaluate(license, "license.type"), equalTo(type));
} catch (ResponseException e) {
throw new AssertionError(e);
}
});
}
private void checkSecurityEnabled(boolean allowAllRealms) throws IOException {

View File

@ -7,6 +7,7 @@ package org.elasticsearch.xpack.security;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseException;
import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.rest.ESRestTestCase;
@ -85,10 +86,17 @@ public class TlsWithBasicLicenseIT extends ESRestTestCase {
client().performRequest(new Request("POST", "/_license/start_basic?acknowledge=true"));
}
private void checkLicenseType(String type) throws IOException {
Map<String, Object> license = getAsMap("/_license");
assertThat(license, notNullValue());
assertThat(ObjectPath.evaluate(license, "license.type"), equalTo(type));
private void checkLicenseType(String type) throws Exception {
assertBusy(() -> {
try {
Map<String, Object> license = getAsMap("/_license");
assertThat(license, notNullValue());
assertThat(ObjectPath.evaluate(license, "license.type"), equalTo(type));
} catch (ResponseException e) {
throw new AssertionError(e);
}
});
}
private void checkSSLEnabled() throws IOException {