File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed
server/src/internalClusterTest/java/org/elasticsearch/search Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -262,12 +262,16 @@ public void testCancelFailedSearchWhenPartialResultDisallowed() throws Exception
262262 // When the search request executes, block all shards except 1.
263263 final List <SearchShardBlockingPlugin > searchShardBlockingPlugins = initSearchShardBlockingPlugin ();
264264 AtomicBoolean letOneShardProceed = new AtomicBoolean ();
265+ // Ensure we have at least one task waiting on the latch
266+ CountDownLatch waitingTaskLatch = new CountDownLatch (1 );
265267 CountDownLatch shardTaskLatch = new CountDownLatch (1 );
266268 for (SearchShardBlockingPlugin plugin : searchShardBlockingPlugins ) {
267269 plugin .setRunOnNewReaderContext ((ReaderContext c ) -> {
268270 if (letOneShardProceed .compareAndSet (false , true )) {
269271 // Let one shard continue.
270272 } else {
273+ // Signal that we have a task waiting on the latch
274+ waitingTaskLatch .countDown ();
271275 safeAwait (shardTaskLatch ); // Block the other shards.
272276 }
273277 });
@@ -280,6 +284,9 @@ public void testCancelFailedSearchWhenPartialResultDisallowed() throws Exception
280284 plugin .disableBlock ();
281285 plugin .setBeforeExecution (() -> {
282286 if (oneThreadWillError .compareAndSet (false , true )) {
287+ // wait for some task to get to the latch
288+ safeAwait (waitingTaskLatch );
289+ // then throw the exception
283290 throw new IllegalStateException ("This will cancel the ContextIndexSearcher.search task" );
284291 }
285292 });
You can’t perform that action at this time.
0 commit comments