[TEST] Wait for pending tasks on test clean up... (elastic/x-pack-elasticsearch#1137)

.. in MlNativeAutodetectIntegTestCase.

We wait for pending tasks to finish from REST tests but not
from the ones using a native autodetect. This commit adds the
waiting in those tests too.

Relates elastic/x-pack-elasticsearch#1136

Original commit: elastic/x-pack-elasticsearch@a7a5455c78
This commit is contained in:
Dimitris Athanasiou 2017-04-20 14:03:38 +01:00 committed by GitHub
parent a2124b68e1
commit 13d3b353c6
1 changed files with 23 additions and 0 deletions

View File

@ -5,9 +5,11 @@
*/ */
package org.elasticsearch.xpack.ml.integration; package org.elasticsearch.xpack.ml.integration;
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest;
import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.test.SecurityIntegTestCase; import org.elasticsearch.test.SecurityIntegTestCase;
import org.elasticsearch.xpack.XPackSettings; import org.elasticsearch.xpack.XPackSettings;
@ -63,6 +65,12 @@ abstract class MlNativeAutodetectIntegTestCase extends SecurityIntegTestCase {
} }
protected void cleanUp() { protected void cleanUp() {
cleanUpDatafeeds();
cleanUpJobs();
waitForPendingTasks();
}
private void cleanUpDatafeeds() {
for (DatafeedConfig datafeed : datafeeds) { for (DatafeedConfig datafeed : datafeeds) {
try { try {
stopDatafeed(datafeed.getId()); stopDatafeed(datafeed.getId());
@ -75,6 +83,9 @@ abstract class MlNativeAutodetectIntegTestCase extends SecurityIntegTestCase {
// ignore // ignore
} }
} }
}
private void cleanUpJobs() {
for (Job.Builder job : jobs) { for (Job.Builder job : jobs) {
try { try {
closeJob(job.getId()); closeJob(job.getId());
@ -89,6 +100,18 @@ abstract class MlNativeAutodetectIntegTestCase extends SecurityIntegTestCase {
} }
} }
private void waitForPendingTasks() {
ListTasksRequest listTasksRequest = new ListTasksRequest();
listTasksRequest.setWaitForCompletion(true);
listTasksRequest.setDetailed(true);
listTasksRequest.setTimeout(TimeValue.timeValueSeconds(10));
try {
admin().cluster().listTasks(listTasksRequest).get();
} catch (Exception e) {
throw new AssertionError("Failed to wait for pending tasks to complete", e);
}
}
protected void registerJob(Job.Builder job) { protected void registerJob(Job.Builder job) {
if (jobs.add(job) == false) { if (jobs.add(job) == false) {
throw new IllegalArgumentException("job [" + job.getId() + "] is already registered"); throw new IllegalArgumentException("job [" + job.getId() + "] is already registered");