Skip to content

Commit

Permalink
Fix ILM history store tests
Browse files Browse the repository at this point in the history
These tests use the same index name, making it hard to read logs when
diagnosing the failures. Additionally more information about the current
state of the index could be retrieved when failing.

This changes these two things in the hope of capturing more data about
why this fails on some CI nodes but not others.

Relates to elastic#50353
  • Loading branch information
dakrone committed Jan 3, 2020
1 parent a5ab7da commit 1cc4b23
Showing 1 changed file with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1077,9 +1077,8 @@ public void testRolloverStepRetriesUntilRolledOverIndexIsDeleted() throws Except
assertBusy(() -> assertThat(getStepKeyForIndex(index), equalTo(TerminalPolicyStep.KEY)));
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/50353")
public void testHistoryIsWrittenWithSuccess() throws Exception {
String index = "index";
String index = "success-index";

createNewSingletonPolicy("hot", new RolloverAction(null, null, 1L));
Request createIndexTemplate = new Request("PUT", "_template/rolling_indexes");
Expand Down Expand Up @@ -1121,9 +1120,8 @@ public void testHistoryIsWrittenWithSuccess() throws Exception {
}


@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/50353")
public void testHistoryIsWrittenWithFailure() throws Exception {
String index = "index";
String index = "failure-index";

createNewSingletonPolicy("hot", new RolloverAction(null, null, 1L));
Request createIndexTemplate = new Request("PUT", "_template/rolling_indexes");
Expand All @@ -1150,9 +1148,8 @@ public void testHistoryIsWrittenWithFailure() throws Exception {
assertBusy(() -> assertHistoryIsPresent(policy, index + "-1", false, "ERROR"), 30, TimeUnit.SECONDS);
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/50353")
public void testHistoryIsWrittenWithDeletion() throws Exception {
String index = "index";
String index = "delete-index";

createNewSingletonPolicy("delete", new DeleteAction());
Request createIndexTemplate = new Request("PUT", "_template/delete_indexes");
Expand Down Expand Up @@ -1231,8 +1228,37 @@ private void assertHistoryIsPresent(String policyName, String indexName, boolean
historyResponseMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true);
}
logger.info("--> history response: {}", historyResponseMap);
assertThat((int)((Map<String, Object>) ((Map<String, Object>) historyResponseMap.get("hits")).get("total")).get("value"),
greaterThanOrEqualTo(1));
int hits = (int)((Map<String, Object>) ((Map<String, Object>) historyResponseMap.get("hits")).get("total")).get("value");

// For a failure, print out whatever history we *do* have for the index
if (hits == 0) {
final Request allResults = new Request("GET", "ilm-history*/_search");
allResults.setJsonEntity("{\n" +
" \"query\": {\n" +
" \"bool\": {\n" +
" \"must\": [\n" +
" {\n" +
" \"term\": {\n" +
" \"policy\": \"" + policyName + "\"\n" +
" }\n" +
" },\n" +
" {\n" +
" \"term\": {\n" +
" \"index\": \"" + indexName + "\"\n" +
" }\n" +
" }\n" +
" ]\n" +
" }\n" +
" }\n" +
"}");
final Response allResultsResp = client().performRequest(historySearchRequest);
Map<String, Object> allResultsMap;
try (InputStream is = allResultsResp.getEntity().getContent()) {
allResultsMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true);
}
logger.info("--> expected at least 1 hit, got 0. All history for index [{}]: {}", index, allResultsMap);
}
assertThat(hits, greaterThanOrEqualTo(1));
} catch (ResponseException e) {
// Throw AssertionError instead of an exception if the search fails so that assertBusy works as expected
logger.error(e);
Expand Down

0 comments on commit 1cc4b23

Please sign in to comment.