From d1ac92a87c4e543abad9bca73f0b54ccc0291cc0 Mon Sep 17 00:00:00 2001 From: Andrei Dan Date: Tue, 8 Dec 2020 17:05:27 +0000 Subject: [PATCH] Fix LifecycleLicenseIT failures (#66039) This attempts to fix the flakiness in the LifecycleLicenseIT tests. This waits for an active license to be available in the cluster (REST layer comes up before) and adds busy waiting for setting/checking the licenses with logging of responses. Co-authored-by: Elastic Machine --- .../xpack/ilm/LifecycleLicenseIT.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/LifecycleLicenseIT.java b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/LifecycleLicenseIT.java index 196eb1b7fe85a..a041dc7fa32c0 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/LifecycleLicenseIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/LifecycleLicenseIT.java @@ -8,6 +8,7 @@ import org.apache.http.util.EntityUtils; import org.elasticsearch.client.Request; +import org.elasticsearch.client.Response; import org.elasticsearch.client.ResponseException; import org.elasticsearch.cluster.metadata.DataStream; import org.elasticsearch.cluster.metadata.Template; @@ -48,9 +49,10 @@ public class LifecycleLicenseIT extends ESRestTestCase { private String dataStream; @Before - public void refreshDatastream() { + public void refreshDatastream() throws Exception { dataStream = "logs-" + randomAlphaOfLength(10).toLowerCase(Locale.ROOT); policy = "policy-" + randomAlphaOfLength(5); + waitForActiveLicense(adminClient()); } @After @@ -130,11 +132,20 @@ private void putTrialLicense() throws Exception { XContentBuilder builder = JsonXContent.contentBuilder(); builder = signedLicense.toXContent(builder, ToXContent.EMPTY_PARAMS); putTrialRequest.setJsonEntity("{\"licenses\":[\n " + Strings.toString(builder) + "\n]}"); - client().performRequest(putTrialRequest); + assertBusy(() -> { + Response putLicenseResponse = client().performRequest(putTrialRequest); + logger.info("put trial license response body is [{}]", EntityUtils.toString(putLicenseResponse.getEntity())); + assertOK(putLicenseResponse); + }); } private void checkCurrentLicenseIs(String type) throws Exception { - assertBusy(() -> assertThat(EntityUtils.toString(client().performRequest(new Request("GET", "/_license")).getEntity()), - containsStringIgnoringCase("\"type\" : \"" + type + "\""))); + assertBusy(() -> { + Response getLicense = client().performRequest(new Request("GET", "/_license")); + String responseBody = EntityUtils.toString(getLicense.getEntity()); + logger.info("get license response body is [{}]", responseBody); + assertThat(responseBody, + containsStringIgnoringCase("\"type\" : \"" + type + "\"")); + }); } }