Skip to content

Commit

Permalink
Increase timeouts in TimeSeriesLifecycleActionsIT#testWaitForSnapshot…
Browse files Browse the repository at this point in the history
… and testWaitForSnapshotSlmExecutedBefore test (#50818)

* 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

* Formatting changes

* Longer timeout
  • Loading branch information
probakowski authored Jan 14, 2020
1 parent f77ff8b commit 36079d4
Showing 1 changed file with 37 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
import org.elasticsearch.xpack.core.ilm.SetPriorityAction;
import org.elasticsearch.xpack.core.ilm.ShrinkAction;
import org.elasticsearch.xpack.core.ilm.ShrinkStep;
import org.elasticsearch.xpack.core.ilm.WaitForSnapshotAction;
import org.elasticsearch.xpack.core.ilm.Step;
import org.elasticsearch.xpack.core.ilm.Step.StepKey;
import org.elasticsearch.xpack.core.ilm.TerminalPolicyStep;
import org.elasticsearch.xpack.core.ilm.UpdateRolloverLifecycleDateStep;
import org.elasticsearch.xpack.core.ilm.WaitForRolloverReadyStep;
import org.elasticsearch.xpack.core.ilm.WaitForSnapshotAction;
import org.hamcrest.Matchers;
import org.junit.Before;

Expand Down Expand Up @@ -324,50 +324,62 @@ public void testAllocateActionOnlyReplicas() throws Exception {
});
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/50781")
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")));
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/50781")
assertBusy(() -> assertThat(getStepKeyForIndex(index).getAction(), equalTo("completed")), 2, TimeUnit.MINUTES);

request = new Request("DELETE", "/_slm/policy/" + smlPolicy);
assertOK(client().performRequest(request));

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")), 2, TimeUnit.MINUTES);

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 {
Expand Down Expand Up @@ -1628,24 +1640,26 @@ 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")
.field("include_global_state", false)
.endObject()
.endObject()));

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()
Expand All @@ -1657,5 +1671,6 @@ private void createSnapshotRepo() throws IOException {
.endObject()
.endObject()));
assertOK(client().performRequest(request));
return repo;
}
}

0 comments on commit 36079d4

Please sign in to comment.