From b1c3ad8f59e99d42d3cc5f13d6764f2f77f77bfb Mon Sep 17 00:00:00 2001 From: Tim Brooks Date: Tue, 7 Jul 2020 14:33:05 -0600 Subject: [PATCH] Fix race in RecoveryRequestTrackerTests (#59187) Currently in the recovery request tracker tests we place the futures into the future map on the GENERIC thread. It is possible that the test has already advanced past the point where we block on these futures before they are placed in the map. This introduces other potential failures as we expect all futures have been completed. This commit fixes the test by places the futures in the map prior to dispatching. --- .../indices/recovery/RecoveryRequestTrackerTests.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryRequestTrackerTests.java b/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryRequestTrackerTests.java index 54eb8eef1a3..22db57c3b5f 100644 --- a/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryRequestTrackerTests.java +++ b/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryRequestTrackerTests.java @@ -59,11 +59,11 @@ public class RecoveryRequestTrackerTests extends ESTestCase { final long seqNo = j; int iterations = randomIntBetween(2, 5); for (int i = 0; i < iterations; ++i) { + PlainActionFuture future = PlainActionFuture.newFuture(); + Set> set = seqToResult.computeIfAbsent(seqNo, (k) -> ConcurrentCollections.newConcurrentSet()); + set.add(future); threadPool.generic().execute(() -> { - PlainActionFuture future = PlainActionFuture.newFuture(); ActionListener listener = requestTracker.markReceivedAndCreateListener(seqNo, future); - Set> set = seqToResult.computeIfAbsent(seqNo, (k) -> ConcurrentCollections.newConcurrentSet()); - set.add(future); if (listener != null) { boolean added = seqNosReturned.add(seqNo); // Ensure that we only return 1 future per sequence number