Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Fix flaky TransportMultiSearchActionTests.testCancellation #17196

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -321,26 +321,24 @@ 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<AssertionError> errorHolder = new AtomicReference<>();
// randomize whether or not requests are executed asynchronously
ExecutorService executorService = threadPool.executor(ThreadPool.Names.GENERIC);
final Set<SearchRequest> 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
public void search(final SearchRequest request, final ActionListener<SearchResponse> listener) {
if (parentTask[0] != null && parentTask[0].isCancelled()) {
fail("Should not execute search after parent task is cancelled");
}
try {
countDownLatch.await(10, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}

requests.add(request);
executorService.execute(() -> {
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(
Expand Down Expand Up @@ -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]);
Expand Down
Loading