Skip to content

Commit a5406e1

Browse files
committed
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.
1 parent b2b02f1 commit a5406e1

File tree

1 file changed

+7
-1
lines changed
  • core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks

1 file changed

+7
-1
lines changed

core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TasksIT.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@
4848
import java.util.HashMap;
4949
import java.util.List;
5050
import java.util.Map;
51+
import java.util.concurrent.CountDownLatch;
5152
import java.util.concurrent.ExecutionException;
53+
import java.util.concurrent.TimeUnit;
5254
import java.util.concurrent.locks.ReentrantLock;
5355
import java.util.function.Function;
5456

@@ -252,11 +254,14 @@ public void testCanFetchIndexStatus() throws InterruptedException, ExecutionExce
252254
*/
253255
ReentrantLock taskFinishLock = new ReentrantLock();
254256
taskFinishLock.lock();
257+
CountDownLatch taskRegistered = new CountDownLatch(1);
255258
for (ClusterService clusterService : internalCluster().getInstances(ClusterService.class)) {
256259
((MockTaskManager)clusterService.getTaskManager()).addListener(new MockTaskManagerListener() {
257260
@Override
258261
public void onTaskRegistered(Task task) {
259-
// Intentional noop
262+
if (task.getAction().startsWith(IndexAction.NAME)) {
263+
taskRegistered.countDown();
264+
}
260265
}
261266

262267
@Override
@@ -275,6 +280,7 @@ public void onTaskUnregistered(Task task) {
275280
});
276281
}
277282
ListenableActionFuture<?> indexFuture = client().prepareIndex("test", "test").setSource("test", "test").execute();
283+
taskRegistered.await(10, TimeUnit.SECONDS); // waiting for at least one task to be registered
278284
ListTasksResponse tasks = client().admin().cluster().prepareListTasks().setActions("indices:data/write/index*").setDetailed(true)
279285
.get();
280286
taskFinishLock.unlock();

0 commit comments

Comments
 (0)