From 50c16f7836f90e8e286d976095ad17b51a99a351 Mon Sep 17 00:00:00 2001 From: Finn Carroll Date: Mon, 9 Sep 2024 20:30:58 +0000 Subject: [PATCH] Wait on async stats before asserting on statsResponse Signed-off-by: Finn Carroll --- .../request/SubmitAsynchronousSearchRequest.java | 2 +- .../integTests/AsynchronousSearchStatsIT.java | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/opensearch/search/asynchronous/request/SubmitAsynchronousSearchRequest.java b/src/main/java/org/opensearch/search/asynchronous/request/SubmitAsynchronousSearchRequest.java index b17d423e..7cb67562 100644 --- a/src/main/java/org/opensearch/search/asynchronous/request/SubmitAsynchronousSearchRequest.java +++ b/src/main/java/org/opensearch/search/asynchronous/request/SubmitAsynchronousSearchRequest.java @@ -42,7 +42,7 @@ public class SubmitAsynchronousSearchRequest extends ActionRequest { private TimeValue waitForCompletionTimeout = DEFAULT_WAIT_FOR_COMPLETION_TIMEOUT; /** - * Determines whether the resource resource should be kept on completion or failure (defaults to false). + * Determines whether the resource should be kept on completion or failure (defaults to false). */ @Nullable private Boolean keepOnCompletion = DEFAULT_KEEP_ON_COMPLETION; diff --git a/src/test/java/org/opensearch/search/asynchronous/integTests/AsynchronousSearchStatsIT.java b/src/test/java/org/opensearch/search/asynchronous/integTests/AsynchronousSearchStatsIT.java index 87b6dc10..e74152da 100644 --- a/src/test/java/org/opensearch/search/asynchronous/integTests/AsynchronousSearchStatsIT.java +++ b/src/test/java/org/opensearch/search/asynchronous/integTests/AsynchronousSearchStatsIT.java @@ -166,11 +166,15 @@ public void testStatsAcrossNodes() throws InterruptedException, ExecutionExcepti TestThreadPool finalThreadPool = threadPool; threads.forEach(t -> finalThreadPool.generic().execute(t)); latch.await(); - AsynchronousSearchStatsResponse statsResponse = client().execute(AsynchronousSearchStatsAction.INSTANCE, - new AsynchronousSearchStatsRequest()).get(); + AtomicLong actualNumSuccesses = new AtomicLong(); AtomicLong actualNumFailures = new AtomicLong(); AtomicLong actualNumPersisted = new AtomicLong(); + + AsynchronousSearchStatsResponse statsResponse = client().execute(AsynchronousSearchStatsAction.INSTANCE, + new AsynchronousSearchStatsRequest()).get(); + waitForAsyncSearchTasksToComplete(); + for (AsynchronousSearchStats node : statsResponse.getNodes()) { AsynchronousSearchCountStats asCountStats = node.getAsynchronousSearchCountStats(); assertEquals(asCountStats.getRunningCount(), 0); @@ -188,7 +192,6 @@ public void testStatsAcrossNodes() throws InterruptedException, ExecutionExcepti assertEquals(expectedNumPersisted.get(), actualNumPersisted.get()); assertEquals(expectedNumFailures.get(), actualNumFailures.get()); assertEquals(expectedNumSuccesses.get(), actualNumSuccesses.get()); - waitForAsyncSearchTasksToComplete(); } finally { ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS); }