Skip to content

Commit 0b30e4a

Browse files
authored
Fix test - wait for other threads before throwing the exception (#124386) (#124427)
(cherry picked from commit b9a9784) # Conflicts: # server/src/internalClusterTest/java/org/elasticsearch/search/SearchCancellationIT.java
1 parent f503dda commit 0b30e4a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

server/src/internalClusterTest/java/org/elasticsearch/search/SearchCancellationIT.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff 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
});

0 commit comments

Comments
 (0)