Skip to content

Commit a76fc32

Browse files
authored
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
1 parent 3270cb3 commit a76fc32

File tree

4 files changed

+38
-13
lines changed

4 files changed

+38
-13
lines changed

docs/src/test/java/org/elasticsearch/smoketest/DocsClientYamlTestSuiteIT.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ protected ClientYamlTestClient initClientYamlTestClient(
104104

105105
@Before
106106
public void waitForRequirements() throws Exception {
107-
if (isCcrTest()) {
107+
if (isCcrTest() || isGetLicenseTest()) {
108108
ESRestTestCase.waitForActiveLicense(adminClient());
109109
}
110110
}
@@ -175,6 +175,11 @@ protected boolean isCcrTest() {
175175
return testName != null && testName.contains("/ccr/");
176176
}
177177

178+
protected boolean isGetLicenseTest() {
179+
String testName = getTestName();
180+
return testName != null && (testName.contains("/get-license/") || testName.contains("\\get-license\\"));
181+
}
182+
178183
/**
179184
* Compares the results of running two analyzers against many random
180185
* strings. The goal is to figure out if two anlayzers are "the same" by

x-pack/plugin/security/qa/basic-enable-security/src/test/java/org/elasticsearch/xpack/security/EnableSecurityOnBasicLicenseIT.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,16 @@ private String getIndices() throws IOException {
9797
return EntityUtils.toString(response.getEntity());
9898
}
9999

100-
private void checkBasicLicenseType() throws IOException {
101-
Map<String, Object> license = getAsMap("/_license");
102-
assertThat(license, notNullValue());
103-
assertThat(ObjectPath.evaluate(license, "license.type"), equalTo("basic"));
100+
private void checkBasicLicenseType() throws Exception {
101+
assertBusy(() -> {
102+
try {
103+
Map<String, Object> license = getAsMap("/_license");
104+
assertThat(license, notNullValue());
105+
assertThat(ObjectPath.evaluate(license, "license.type"), equalTo("basic"));
106+
} catch (ResponseException e) {
107+
throw new AssertionError(e);
108+
}
109+
});
104110
}
105111

106112
private void checkSecurityStatus(boolean expectEnabled) throws IOException {

x-pack/plugin/security/qa/security-basic/src/test/java/org/elasticsearch/xpack/security/SecurityWithBasicLicenseIT.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,16 @@ private void revertTrial() throws IOException {
7777
client().performRequest(new Request("POST", "/_license/start_basic?acknowledge=true"));
7878
}
7979

80-
private void checkLicenseType(String type) throws IOException {
81-
Map<String, Object> license = getAsMap("/_license");
82-
assertThat(license, notNullValue());
83-
assertThat(ObjectPath.evaluate(license, "license.type"), equalTo(type));
80+
private void checkLicenseType(String type) throws Exception {
81+
assertBusy(() -> {
82+
try {
83+
Map<String, Object> license = getAsMap("/_license");
84+
assertThat(license, notNullValue());
85+
assertThat(ObjectPath.evaluate(license, "license.type"), equalTo(type));
86+
} catch (ResponseException e) {
87+
throw new AssertionError(e);
88+
}
89+
});
8490
}
8591

8692
private void checkSecurityEnabled(boolean allowAllRealms) throws IOException {

x-pack/plugin/security/qa/tls-basic/src/test/java/org/elasticsearch/xpack/security/TlsWithBasicLicenseIT.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import org.elasticsearch.client.Request;
99
import org.elasticsearch.client.Response;
10+
import org.elasticsearch.client.ResponseException;
1011
import org.elasticsearch.common.io.PathUtils;
1112
import org.elasticsearch.common.settings.Settings;
1213
import org.elasticsearch.test.rest.ESRestTestCase;
@@ -85,10 +86,17 @@ private void revertTrial() throws IOException {
8586
client().performRequest(new Request("POST", "/_license/start_basic?acknowledge=true"));
8687
}
8788

88-
private void checkLicenseType(String type) throws IOException {
89-
Map<String, Object> license = getAsMap("/_license");
90-
assertThat(license, notNullValue());
91-
assertThat(ObjectPath.evaluate(license, "license.type"), equalTo(type));
89+
private void checkLicenseType(String type) throws Exception {
90+
assertBusy(() -> {
91+
try {
92+
Map<String, Object> license = getAsMap("/_license");
93+
assertThat(license, notNullValue());
94+
assertThat(ObjectPath.evaluate(license, "license.type"), equalTo(type));
95+
} catch (ResponseException e) {
96+
throw new AssertionError(e);
97+
}
98+
});
99+
92100
}
93101

94102
private void checkSSLEnabled() throws IOException {

0 commit comments

Comments
 (0)