diff --git a/core/src/test/java/org/elasticsearch/index/replication/RecoveryDuringReplicationTests.java b/core/src/test/java/org/elasticsearch/index/replication/RecoveryDuringReplicationTests.java index b0988d9cf9a5c..89916fcc921df 100644 --- a/core/src/test/java/org/elasticsearch/index/replication/RecoveryDuringReplicationTests.java +++ b/core/src/test/java/org/elasticsearch/index/replication/RecoveryDuringReplicationTests.java @@ -58,10 +58,12 @@ import java.util.concurrent.atomic.AtomicReference; import static org.hamcrest.Matchers.anyOf; +import static org.hamcrest.Matchers.both; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.lessThan; +import static org.hamcrest.Matchers.lessThanOrEqualTo; import static org.hamcrest.Matchers.not; public class RecoveryDuringReplicationTests extends ESIndexLevelReplicationTestCase { @@ -390,7 +392,8 @@ public long indexTranslogOperations(List operations, int tot recoveryStart.await(); // index some more - docs += shards.indexDocs(randomInt(5)); + final int indexedDuringRecovery = shards.indexDocs(randomInt(5)); + docs += indexedDuringRecovery; assertFalse("recovery should wait on pending docs", opsSent.get()); @@ -401,7 +404,9 @@ public long indexTranslogOperations(List operations, int tot recoveryFuture.get(); assertThat(newReplica.recoveryState().getIndex().fileDetails(), empty()); - assertThat(newReplica.recoveryState().getTranslog().recoveredOperations(), equalTo(docs)); + assertThat(newReplica.recoveryState().getTranslog().recoveredOperations(), + // we don't know which of the inflight operations made it into the translog range we re-play + both(greaterThanOrEqualTo(docs-indexedDuringRecovery)).and(lessThanOrEqualTo(docs))); shards.assertAllEqual(docs); } finally {