From a5406e1ffa28a76942bffdeba232d3652e4aff72 Mon Sep 17 00:00:00 2001 From: Igor Motov Date: Wed, 10 Feb 2016 10:38:35 -0500 Subject: [PATCH] Adds wait for task registration to testCanFetchIndexStatus In the testCanFetchIndexStatus the task check can occur before the indexing process is started making the test to fail. This commit adds an additional lock to make sure we check tasks only after at least one of the tasks is registered. --- .../action/admin/cluster/node/tasks/TasksIT.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TasksIT.java b/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TasksIT.java index 17be1677869..d35704a9353 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TasksIT.java +++ b/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TasksIT.java @@ -48,7 +48,9 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; import java.util.function.Function; @@ -252,11 +254,14 @@ public class TasksIT extends ESIntegTestCase { */ ReentrantLock taskFinishLock = new ReentrantLock(); taskFinishLock.lock(); + CountDownLatch taskRegistered = new CountDownLatch(1); for (ClusterService clusterService : internalCluster().getInstances(ClusterService.class)) { ((MockTaskManager)clusterService.getTaskManager()).addListener(new MockTaskManagerListener() { @Override public void onTaskRegistered(Task task) { - // Intentional noop + if (task.getAction().startsWith(IndexAction.NAME)) { + taskRegistered.countDown(); + } } @Override @@ -275,6 +280,7 @@ public class TasksIT extends ESIntegTestCase { }); } ListenableActionFuture indexFuture = client().prepareIndex("test", "test").setSource("test", "test").execute(); + taskRegistered.await(10, TimeUnit.SECONDS); // waiting for at least one task to be registered ListTasksResponse tasks = client().admin().cluster().prepareListTasks().setActions("indices:data/write/index*").setDetailed(true) .get(); taskFinishLock.unlock();