Skip to content

Commit 2da66b8

Browse files
smalyshevgeorgewallace
authored andcommitted
Fix test - wait for other threads before throwing the exception (elastic#124386)
1 parent 3f96715 commit 2da66b8

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,17 @@ 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 {
271-
safeAwait(shardTaskLatch, TimeValue.timeValueSeconds(30)); // Block the other shards.
273+
// Signal that we have a task waiting on the latch
274+
waitingTaskLatch.countDown();
275+
safeAwait(shardTaskLatch); // Block the other shards.
272276
}
273277
});
274278
}
@@ -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)