Skip to content

Commit 1e29fb3

Browse files
authored
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
1 parent 71d43b5 commit 1e29fb3

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

server/src/test/java/org/elasticsearch/action/support/ListenableActionFutureTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ protected void doRun() {
6868
}
6969
}
7070

71-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/68772")
7271
public void testListenersNotifiedOnCorrectThreads() throws InterruptedException {
7372

7473
final int adderThreads = between(1, 5);
@@ -90,7 +89,10 @@ public void testListenersNotifiedOnCorrectThreads() throws InterruptedException
9089
awaitSafe(barrier);
9190

9291
final AtomicBoolean isComplete = new AtomicBoolean();
93-
if (postComplete.get()) {
92+
if (completerThreads == 1 && postComplete.get()) {
93+
// If there are multiple completer threads then onResponse might return on one thread, and hence postComplete is
94+
// set, before the other completer thread notifies all the listeners. OTOH with one completer thread we know that
95+
// postComplete indicates that the listeners were already notified.
9496
future.addListener(new ActionListener<>() {
9597
@Override
9698
public void onResponse(Void response) {

0 commit comments

Comments
 (0)