From cf235796c08caef72dc80a9a4efe3ba8acada5ca Mon Sep 17 00:00:00 2001 From: Gordon Brown Date: Tue, 29 Oct 2019 09:33:14 -0700 Subject: [PATCH] Use more reliable "never run" cron pattern in tests (#48608) The cron schedule "1 2 3 4 5 ?" will run every May 4 at 03:02:01, which may result in unnecessary test failures once a year. This commit switches out uses of that schedule in tests for one which will never execute (because it specifies a day which doesn't exist, Feb. 31). Also factors the schedule out to a constant to make the intent clearer. --- .../elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java | 7 ++++--- .../xpack/slm/SLMSnapshotBlockingIntegTests.java | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java b/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java index 49aa397b0f4..e4a38c69ab6 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java @@ -58,6 +58,7 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.startsWith; public class SnapshotLifecycleRestIT extends ESRestTestCase { + private static final String NEVER_EXECUTE_CRON_SCHEDULE = "* * * 31 FEB ? *"; @Override protected boolean waitForAllSnapshotsWiped() { @@ -206,7 +207,7 @@ public class SnapshotLifecycleRestIT extends ESRestTestCase { // Create a snapshot repo initializeRepo(repoId); - createSnapshotPolicy(policyName, "snap", "1 2 3 4 5 ?", repoId, indexName, true); + createSnapshotPolicy(policyName, "snap", NEVER_EXECUTE_CRON_SCHEDULE, repoId, indexName, true); ResponseException badResp = expectThrows(ResponseException.class, () -> client().performRequest(new Request("POST", "/_slm/policy/" + policyName + "-bad/_execute"))); @@ -350,7 +351,7 @@ public class SnapshotLifecycleRestIT extends ESRestTestCase { initializeRepo(repoId); // Create a policy with a retention period of 1 millisecond - createSnapshotPolicy(policyName, "snap", "1 2 3 4 5 ?", repoId, indexName, true, + createSnapshotPolicy(policyName, "snap", NEVER_EXECUTE_CRON_SCHEDULE, repoId, indexName, true, new SnapshotRetentionConfiguration(TimeValue.timeValueMillis(1), null, null)); // Manually create a snapshot @@ -446,7 +447,7 @@ public class SnapshotLifecycleRestIT extends ESRestTestCase { // Create a snapshot repo initializeRepo("repo"); // Create a policy with a retention period of 1 millisecond - createSnapshotPolicy("policy", "snap", "1 2 3 4 5 ?", "repo", "*", true, + createSnapshotPolicy("policy", "snap", NEVER_EXECUTE_CRON_SCHEDULE, "repo", "*", true, new SnapshotRetentionConfiguration(TimeValue.timeValueMillis(1), null, null)); final String snapshotName = executePolicy("policy"); diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SLMSnapshotBlockingIntegTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SLMSnapshotBlockingIntegTests.java index 60f5b22f25c..51ab9e0a790 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SLMSnapshotBlockingIntegTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SLMSnapshotBlockingIntegTests.java @@ -61,6 +61,7 @@ import static org.hamcrest.Matchers.greaterThan; */ @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0) public class SLMSnapshotBlockingIntegTests extends ESIntegTestCase { + private static final String NEVER_EXECUTE_CRON_SCHEDULE = "* * * 31 FEB ? *"; private static final String REPO = "repo-id"; List dataNodeNames = null; @@ -121,7 +122,7 @@ public class SLMSnapshotBlockingIntegTests extends ESIntegTestCase { initializeRepo(REPO); logger.info("--> creating policy {}", policyName); - createSnapshotPolicy(policyName, "snap", "1 2 3 4 5 ?", REPO, indexName, true); + createSnapshotPolicy(policyName, "snap", NEVER_EXECUTE_CRON_SCHEDULE, REPO, indexName, true); logger.info("--> blocking master from completing snapshot"); blockAllDataNodes(REPO); @@ -169,7 +170,7 @@ public class SLMSnapshotBlockingIntegTests extends ESIntegTestCase { initializeRepo(REPO); logger.info("--> creating policy {}", policyId); - createSnapshotPolicy(policyId, "snap", "1 2 3 4 5 ?", REPO, indexName, true, + createSnapshotPolicy(policyId, "snap", NEVER_EXECUTE_CRON_SCHEDULE, REPO, indexName, true, false, new SnapshotRetentionConfiguration(TimeValue.timeValueSeconds(0), null, null)); // Create a snapshot and wait for it to be complete (need something that can be deleted) @@ -297,7 +298,7 @@ public class SLMSnapshotBlockingIntegTests extends ESIntegTestCase { // Create a snapshot repo initializeRepo(REPO); - createSnapshotPolicy(policyId, "snap", "1 2 3 4 5 ?", REPO, indexName, true, + createSnapshotPolicy(policyId, "snap", NEVER_EXECUTE_CRON_SCHEDULE, REPO, indexName, true, partialSuccess, new SnapshotRetentionConfiguration(null, 1, 2)); // Create a failed snapshot