diff --git a/server/src/test/java/org/elasticsearch/indices/recovery/PeerRecoveryTargetServiceTests.java b/server/src/test/java/org/elasticsearch/indices/recovery/PeerRecoveryTargetServiceTests.java index 0db222c14ea..18bf8c8e225 100644 --- a/server/src/test/java/org/elasticsearch/indices/recovery/PeerRecoveryTargetServiceTests.java +++ b/server/src/test/java/org/elasticsearch/indices/recovery/PeerRecoveryTargetServiceTests.java @@ -177,11 +177,13 @@ public class PeerRecoveryTargetServiceTests extends IndexShardTestCase { Optional safeCommit = shard.store().findSafeIndexCommit(globalCheckpoint); assertTrue(safeCommit.isPresent()); int expectedTotalLocal = 0; - try (Translog.Snapshot snapshot = getTranslog(shard).newSnapshot(safeCommit.get().localCheckpoint + 1, globalCheckpoint)) { - Translog.Operation op; - while ((op = snapshot.next()) != null) { - if (op.seqNo() <= globalCheckpoint) { - expectedTotalLocal++; + if (safeCommit.get().localCheckpoint < globalCheckpoint) { + try (Translog.Snapshot snapshot = getTranslog(shard).newSnapshot(safeCommit.get().localCheckpoint + 1, globalCheckpoint)) { + Translog.Operation op; + while ((op = snapshot.next()) != null) { + if (op.seqNo() <= globalCheckpoint) { + expectedTotalLocal++; + } } } }