Skip to content

Commit

Permalink
7582: Fix broken PivotBlockRetrieverTest
Browse files Browse the repository at this point in the history
Signed-off-by: Matilda Clerke <[email protected]>
  • Loading branch information
Matilda-Clerke committed Dec 15, 2024
1 parent 8c0df49 commit 0bfb774
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -175,7 +174,6 @@ private CompletableFuture<BlockHeader> executePivotQuery(final long blockNumber)
// Stop loop if this task is done
return CompletableFuture.failedFuture(new CancellationException());
}

final Optional<RetryingGetHeaderFromPeerByNumberTask> query = createPivotQuery(blockNumber);
final CompletableFuture<BlockHeader> pivotHeaderFuture;
if (query.isPresent()) {
Expand All @@ -187,12 +185,18 @@ private CompletableFuture<BlockHeader> executePivotQuery(final long blockNumber)
LOG.debug("No peer currently available to query for block {}.", blockNumber);
pivotHeaderFuture =
ethContext
.getEthPeers()
.waitForPeer((peer) -> !pivotBlockQueriesByPeerId.containsKey(peer.nodeId()))
.orTimeout(5, TimeUnit.SECONDS)
// Ignore result, ensure even a timeout will result in calling executePivotQuery
.handle((r, e) -> null)
.thenCompose(res -> executePivotQuery(blockNumber));
.getScheduler()
.scheduleFutureTask(
() ->
ethContext
.getEthPeers()
.waitForPeer(
(peer) -> !pivotBlockQueriesByPeerId.containsKey(peer.nodeId()))
// Ignore result, ensure even a timeout will result in calling
// executePivotQuery
.handle((r, e) -> null)
.thenCompose(res -> executePivotQuery(blockNumber)),
Duration.ofSeconds(5));
}

return pivotHeaderFuture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public void shouldIgnorePeersThatDoNotHaveThePivotBlock(final DataStorageFormat
// Add new peer that we can query
final RespondingEthPeer respondingPeerB =
EthProtocolManagerTestUtil.createPeer(ethProtocolManager, 1000);
EthProtocolManagerTestUtil.runPendingFutures(ethProtocolManager);
respondingPeerB.respond(responder);

// We need one more responsive peer before we're done
Expand All @@ -174,6 +175,7 @@ public void shouldIgnorePeersThatDoNotHaveThePivotBlock(final DataStorageFormat
// Add new peer that we can query
final RespondingEthPeer respondingPeerC =
EthProtocolManagerTestUtil.createPeer(ethProtocolManager, 1000);
EthProtocolManagerTestUtil.runPendingFutures(ethProtocolManager);
respondingPeerC.respond(responder);
assertThat(badPeerA.hasOutstandingRequests()).isFalse();
assertThat(badPeerB.hasOutstandingRequests()).isFalse();
Expand Down

0 comments on commit 0bfb774

Please sign in to comment.