From 7e62eb6255e71a2b0bb54181facf2ebf599be849 Mon Sep 17 00:00:00 2001 From: Dimitrios Athanasiou Date: Thu, 27 Apr 2017 12:57:07 +0100 Subject: [PATCH] [TEST] Wait for job to close from DatafeedJobsIT.testLookbackOnly relates elastic/x-pack-elasticsearch#1228 Original commit: elastic/x-pack-elasticsearch@77055bd1287fea8c21a8a92f2a6d11f3b7e20450 --- .../xpack/ml/action/DatafeedJobsIT.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/action/DatafeedJobsIT.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/action/DatafeedJobsIT.java index b86c3708acb..b4018f26a27 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/action/DatafeedJobsIT.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/action/DatafeedJobsIT.java @@ -165,6 +165,8 @@ public class DatafeedJobsIT extends SecurityIntegTestCase { GetDatafeedsStatsAction.Response response = client().execute(GetDatafeedsStatsAction.INSTANCE, request).actionGet(); assertThat(response.getResponse().results().get(0).getDatafeedState(), equalTo(DatafeedState.STOPPED)); }, 60, TimeUnit.SECONDS); + + waitUntilJobIsClosed(job.getId()); } public void testRealtime() throws Exception { @@ -228,4 +230,15 @@ public class DatafeedJobsIT extends SecurityIntegTestCase { }); } + private void waitUntilJobIsClosed(String jobId) throws Exception { + assertBusy(() -> { + try { + GetJobsStatsAction.Request request = new GetJobsStatsAction.Request(jobId); + GetJobsStatsAction.Response response = client().execute(GetJobsStatsAction.INSTANCE, request).get(); + assertThat(response.getResponse().results().get(0).getState(), equalTo(JobState.CLOSED)); + } catch (Exception e) { + throw new RuntimeException(e); + } + }, 30, TimeUnit.SECONDS); + } }