diff --git a/server/src/test/java/org/opensearch/action/search/TransportMultiSearchActionTests.java b/server/src/test/java/org/opensearch/action/search/TransportMultiSearchActionTests.java index 45980e7137ce4..f969313b71833 100644 --- a/server/src/test/java/org/opensearch/action/search/TransportMultiSearchActionTests.java +++ b/server/src/test/java/org/opensearch/action/search/TransportMultiSearchActionTests.java @@ -321,11 +321,8 @@ public TaskManager getTaskManager() { // and if there are more searches than is allowed create an error and remember that. int maxAllowedConcurrentSearches = 1; // Allow 1 search at a time. AtomicInteger counter = new AtomicInteger(); - AtomicReference errorHolder = new AtomicReference<>(); - // randomize whether or not requests are executed asynchronously ExecutorService executorService = threadPool.executor(ThreadPool.Names.GENERIC); - final Set requests = Collections.newSetFromMap(Collections.synchronizedMap(new IdentityHashMap<>())); - CountDownLatch countDownLatch = new CountDownLatch(1); + CountDownLatch canceledLatch = new CountDownLatch(1); CancellableTask[] parentTask = new CancellableTask[1]; NodeClient client = new NodeClient(settings, threadPool) { @Override @@ -333,14 +330,15 @@ public void search(final SearchRequest request, final ActionListener { + try { + if (!canceledLatch.await(1, TimeUnit.SECONDS)) { + fail("Latch should have counted down"); + } + } catch (InterruptedException e) { + throw new RuntimeException(e); + } counter.decrementAndGet(); listener.onResponse( new SearchResponse( @@ -399,7 +397,7 @@ public void onFailure(Task task, Exception e) { } }); parentTask[0].cancel("Giving up"); - countDownLatch.countDown(); + canceledLatch.countDown(); assertNull(responses[0]); assertNull(exceptions[0]);