From 28b3a6e9a96dd1cf9dd068f12796ab4eb3e4307d Mon Sep 17 00:00:00 2001 From: Jan Kuipers Date: Thu, 16 Jan 2025 17:13:09 +0100 Subject: [PATCH] backport datafeeds test fixes (#120289) * Fix(?) and unmute DatafeedJobsRestIT. (#119839) * Fix(?) and unmute DatafeedJobsRestIT. * [CI] Auto commit changes from spotless --------- Co-authored-by: elasticsearchmachine * Datafeed jobs it wait for task cancel (#120177) * Fix task cancellation in DatafeedJobsIT. * fix * unmute DatafeedJobsIT * unmute --------- Co-authored-by: elasticsearchmachine --- muted-tests.yml | 2 -- .../xpack/ml/integration/DatafeedJobsIT.java | 9 +++++++ .../ml/integration/DatafeedJobsRestIT.java | 25 +++++++++---------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/muted-tests.yml b/muted-tests.yml index 06229f9f0bd2a..ad9be1d1196f6 100644 --- a/muted-tests.yml +++ b/muted-tests.yml @@ -257,8 +257,6 @@ tests: - class: org.elasticsearch.xpack.inference.rest.ServerSentEventsRestActionListenerTests method: testNoStream issue: https://github.com/elastic/elasticsearch/issues/114788 -- class: org.elasticsearch.xpack.ml.integration.DatafeedJobsRestIT - issue: https://github.com/elastic/elasticsearch/issues/111319 - class: org.elasticsearch.xpack.restart.CoreFullClusterRestartIT method: testSnapshotRestore {cluster=UPGRADED} issue: https://github.com/elastic/elasticsearch/issues/111799 diff --git a/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/DatafeedJobsIT.java b/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/DatafeedJobsIT.java index 5287d149fae3d..caba356f82ee2 100644 --- a/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/DatafeedJobsIT.java +++ b/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/DatafeedJobsIT.java @@ -11,6 +11,8 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.ResourceNotFoundException; +import org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksRequest; +import org.elasticsearch.action.admin.cluster.node.tasks.cancel.TransportCancelTasksAction; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.common.ReferenceDocs; @@ -80,6 +82,13 @@ public class DatafeedJobsIT extends MlNativeAutodetectIntegTestCase { public void cleanup() { updateClusterSettings(Settings.builder().putNull("logger.org.elasticsearch.xpack.ml.datafeed")); cleanUp(); + // Race conditions between closing and killing tasks in these tests, + // sometimes result in lingering persistent close tasks, which cause + // subsequent tests to fail. Therefore, they're explicitly cancelled. + CancelTasksRequest cancelTasksRequest = new CancelTasksRequest(); + cancelTasksRequest.setActions("*close*"); + cancelTasksRequest.setWaitForCompletion(true); + client().execute(TransportCancelTasksAction.TYPE, cancelTasksRequest).actionGet(); } public void testLookbackOnly() throws Exception { diff --git a/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/DatafeedJobsRestIT.java b/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/DatafeedJobsRestIT.java index 2fc9a80ae3679..804033ef531b9 100644 --- a/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/DatafeedJobsRestIT.java +++ b/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/DatafeedJobsRestIT.java @@ -37,7 +37,6 @@ import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.not; public class DatafeedJobsRestIT extends ESRestTestCase { @@ -503,12 +502,12 @@ public void testLookbackWithIndicesOptions() throws Exception { }"""); client().performRequest(createJobRequest); String datafeedId = jobId + "-datafeed"; - new DatafeedBuilder(datafeedId, jobId, "*hidden-*").setIndicesOptions(""" + new DatafeedBuilder(datafeedId, jobId, "hidden-*").setIndicesOptions(""" {"expand_wildcards": ["all"],"allow_no_indices": true}""").build(); StringBuilder bulk = new StringBuilder(); - Request createGeoData = new Request("PUT", "/.hidden-index"); + Request createGeoData = new Request("PUT", "/hidden-index"); createGeoData.setJsonEntity(""" { "mappings": { @@ -528,23 +527,23 @@ public void testLookbackWithIndicesOptions() throws Exception { client().performRequest(createGeoData); bulk.append(""" - {"index": {"_index": ".hidden-index", "_id": 1}} + {"index": {"_index": "hidden-index", "_id": 1}} {"time":"2016-06-01T00:00:00Z","value": 1000} - {"index": {"_index": ".hidden-index", "_id": 2}} + {"index": {"_index": "hidden-index", "_id": 2}} {"time":"2016-06-01T00:05:00Z","value":1500} - {"index": {"_index": ".hidden-index", "_id": 3}} + {"index": {"_index": "hidden-index", "_id": 3}} {"time":"2016-06-01T00:10:00Z","value":1600} - {"index": {"_index": ".hidden-index", "_id": 4}} + {"index": {"_index": "hidden-index", "_id": 4}} {"time":"2016-06-01T00:15:00Z","value":100} - {"index": {"_index": ".hidden-index", "_id": 5}} + {"index": {"_index": "hidden-index", "_id": 5}} {"time":"2016-06-01T00:20:00Z","value":1} - {"index": {"_index": ".hidden-index", "_id": 6}} + {"index": {"_index": "hidden-index", "_id": 6}} {"time":"2016-06-01T00:25:00Z","value":1500} - {"index": {"_index": ".hidden-index", "_id": 7}} + {"index": {"_index": "hidden-index", "_id": 7}} {"time":"2016-06-01T00:30:00Z","value":1500} - {"index": {"_index": ".hidden-index", "_id": 8}} + {"index": {"_index": "hidden-index", "_id": 8}} {"time":"2016-06-01T00:40:00Z","value":2100} - {"index": {"_index": ".hidden-index", "_id": 9}} + {"index": {"_index": "hidden-index", "_id": 9}} {"time":"2016-06-01T00:41:00Z","value":0} """); bulkIndex(bulk.toString()); @@ -1802,7 +1801,7 @@ private void bulkIndex(String bulk) throws IOException { bulkRequest.addParameter("refresh", "true"); bulkRequest.addParameter("pretty", null); String bulkResponse = EntityUtils.toString(client().performRequest(bulkRequest).getEntity()); - assertThat(bulkResponse, not(containsString("\"errors\": false"))); + assertThat(bulkResponse, containsString("\"errors\" : false")); } private Response createJobAndDataFeed(String jobId, String datafeedId) throws IOException {