From 323bbb835632daae0de6e0de6b0d5121487d290b Mon Sep 17 00:00:00 2001 From: Przemko Robakowski Date: Thu, 9 Jan 2020 21:09:23 +0100 Subject: [PATCH] Fix flaky TimeSeriesLifecycleActionsIT#testWaitForSnapshot test This change adds some randomness and cleanup step to TimeSeriesLifecycleActionsIT#testWaitForSnapshot and testWaitForSnapshotSlmExecutedBefore tests in attempt to make them stable. Reletes to #50781 --- .../ilm/TimeSeriesLifecycleActionsIT.java | 53 ++++++++++++------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java b/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java index 6d11c151e4e7e..4b1771d374774 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java @@ -327,45 +327,58 @@ public void testAllocateActionOnlyReplicas() throws Exception { public void testWaitForSnapshot() throws Exception { createIndexWithSettings(index, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)); - createNewSingletonPolicy("delete", new WaitForSnapshotAction("slm")); + String smlPolicy = randomAlphaOfLengthBetween(4,10); + createNewSingletonPolicy("delete", new WaitForSnapshotAction(smlPolicy)); updatePolicy(index, policy); assertBusy(() -> assertThat(getStepKeyForIndex(index).getAction(), equalTo("wait_for_snapshot"))); - assertBusy(() -> assertThat(getStepKeyForIndex(index).getName(), equalTo("wait-for-snapshot"))); assertBusy(() -> assertThat(getFailedStepForIndex(index), equalTo("wait-for-snapshot"))); - createSnapshotRepo(); - createSlmPolicy(); + String repo = createSnapshotRepo(); + createSlmPolicy(smlPolicy, repo); assertBusy(() -> assertThat(getStepKeyForIndex(index).getAction(), equalTo("wait_for_snapshot"))); - Request request = new Request("PUT", "/_slm/policy/slm/_execute"); + Request request = new Request("PUT", "/_slm/policy/"+smlPolicy+"/_execute"); + assertOK(client().performRequest(request)); + + assertBusy(() -> assertThat(getStepKeyForIndex(index).getAction(), equalTo("completed")),20, TimeUnit.SECONDS); + + request = new Request("DELETE", "/_slm/policy/" + smlPolicy); assertOK(client().performRequest(request)); - assertBusy(() -> assertThat(getStepKeyForIndex(index).getAction(), equalTo("completed"))); + request = new Request("DELETE", "/_snapshot/" + repo); + assertOK(client().performRequest(request)); } public void testWaitForSnapshotSlmExecutedBefore() throws Exception { createIndexWithSettings(index, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)); - createNewSingletonPolicy("delete", new WaitForSnapshotAction("slm")); + String smlPolicy = randomAlphaOfLengthBetween(4, 10); + createNewSingletonPolicy("delete", new WaitForSnapshotAction(smlPolicy)); - createSnapshotRepo(); - createSlmPolicy(); + String repo = createSnapshotRepo(); + createSlmPolicy(smlPolicy, repo); - Request request = new Request("PUT", "/_slm/policy/slm/_execute"); + Request request = new Request("PUT", "/_slm/policy/" + smlPolicy + "/_execute"); assertOK(client().performRequest(request)); updatePolicy(index, policy); assertBusy(() -> assertThat(getStepKeyForIndex(index).getAction(), equalTo("wait_for_snapshot"))); assertBusy(() -> assertThat(getStepKeyForIndex(index).getName(), equalTo("wait-for-snapshot"))); - - request = new Request("PUT", "/_slm/policy/slm/_execute"); + + request = new Request("PUT", "/_slm/policy/" + smlPolicy + "/_execute"); assertOK(client().performRequest(request)); - request = new Request("PUT", "/_slm/policy/slm/_execute"); + request = new Request("PUT", "/_slm/policy/" + smlPolicy + "/_execute"); assertOK(client().performRequest(request)); - assertBusy(() -> assertThat(getStepKeyForIndex(index).getAction(), equalTo("completed"))); + assertBusy(() -> assertThat(getStepKeyForIndex(index).getAction(), equalTo("completed")), 20, TimeUnit.SECONDS); + + request = new Request("DELETE", "/_slm/policy/" + smlPolicy); + assertOK(client().performRequest(request)); + + request = new Request("DELETE", "/_snapshot/" + repo); + assertOK(client().performRequest(request)); } public void testDelete() throws Exception { @@ -1632,14 +1645,14 @@ private String getSnapshotState(String snapshot) throws IOException { return (String) snapResponse.get("state"); } - private void createSlmPolicy() throws IOException { + private void createSlmPolicy(String smlPolicy, String repo) throws IOException { Request request; - request = new Request("PUT", "/_slm/policy/slm"); + request = new Request("PUT", "/_slm/policy/" + smlPolicy); request.setJsonEntity(Strings .toString(JsonXContent.contentBuilder() .startObject() .field("schedule", "59 59 23 31 12 ? 2099") - .field("repository", "repo") + .field("repository", repo) .field("name", "snap" + randomAlphaOfLengthBetween(5, 10).toLowerCase(Locale.ROOT)) .startObject("config") .endObject() @@ -1648,8 +1661,9 @@ private void createSlmPolicy() throws IOException { assertOK(client().performRequest(request)); } - private void createSnapshotRepo() throws IOException { - Request request = new Request("PUT", "/_snapshot/repo"); + private String createSnapshotRepo() throws IOException { + String repo = randomAlphaOfLengthBetween(4, 10); + Request request = new Request("PUT", "/_snapshot/" + repo); request.setJsonEntity(Strings .toString(JsonXContent.contentBuilder() .startObject() @@ -1661,5 +1675,6 @@ private void createSnapshotRepo() throws IOException { .endObject() .endObject())); assertOK(client().performRequest(request)); + return repo; } }