From fd8552889004fa2cc2388e0815c55f8e6c8ec0c9 Mon Sep 17 00:00:00 2001 From: David Turner Date: Wed, 10 Feb 2021 09:47:25 +0000 Subject: [PATCH] Fix testListenersNotifiedOnCorrectThreads (#68805) This test assumed, incorrectly, that `future#done()` completes before `future#set()` returns, but this isn't true if there are multiple threads racing to complete the future. In other words listeners added before calling `onResponse()` are not necessarily notified by the time `onResponse()` returns. This commit fixes the test to account for this subtle point. Closes #68772 --- .../action/support/ListenableActionFutureTests.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/action/support/ListenableActionFutureTests.java b/server/src/test/java/org/elasticsearch/action/support/ListenableActionFutureTests.java index 1ebd7fab99f9e..a9f62d0e439e8 100644 --- a/server/src/test/java/org/elasticsearch/action/support/ListenableActionFutureTests.java +++ b/server/src/test/java/org/elasticsearch/action/support/ListenableActionFutureTests.java @@ -68,7 +68,6 @@ protected void doRun() { } } - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/68772") public void testListenersNotifiedOnCorrectThreads() throws InterruptedException { final int adderThreads = between(1, 5); @@ -90,7 +89,10 @@ public void testListenersNotifiedOnCorrectThreads() throws InterruptedException awaitSafe(barrier); final AtomicBoolean isComplete = new AtomicBoolean(); - if (postComplete.get()) { + if (completerThreads == 1 && postComplete.get()) { + // If there are multiple completer threads then onResponse might return on one thread, and hence postComplete is + // set, before the other completer thread notifies all the listeners. OTOH with one completer thread we know that + // postComplete indicates that the listeners were already notified. future.addListener(new ActionListener() { @Override public void onResponse(Void response) {