Skip to content

Commit

Permalink
Fix NullPointerException - complete future with fast sync state not n…
Browse files Browse the repository at this point in the history
…ull. (PegaSysEng#859)
  • Loading branch information
ajsutton authored and tmohay committed Feb 15, 2019
1 parent 04ce6f2 commit dbd4467
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public CompletableFuture<FastSyncState> waitForSuitablePeers(final FastSyncState
if (ethContext.getEthPeers().availablePeerCount() > 0) {
LOG.warn(
"Fast sync timed out before minimum peer count was reached. Continuing with reduced peers.");
result.complete(null);
result.complete(fastSyncState);
} else {
LOG.warn(
"Maximum wait time for fast sync reached but no peers available. Continuing to wait for any available peer.");
Expand All @@ -98,7 +98,7 @@ public CompletableFuture<FastSyncState> waitForSuitablePeers(final FastSyncState
LOG.error("Failed to find peers for fast sync", error);
result.completeExceptionally(error);
} else {
result.complete(null);
result.complete(fastSyncState);
}
return null;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,15 @@ public void waitForPeersShouldSucceedIfEnoughPeersAreFound() {
}
final CompletableFuture<FastSyncState> result =
fastSyncActions.waitForSuitablePeers(EMPTY_SYNC_STATE);
assertThat(result).isCompleted();
assertThat(result).isCompletedWithValue(EMPTY_SYNC_STATE);
}

@Test
public void waitForPeersShouldReportSuccessWhenTimeLimitReachedAndAPeerIsAvailable() {
EthProtocolManagerTestUtil.createPeer(ethProtocolManager);
timeoutCount.set(Integer.MAX_VALUE);
assertThat(fastSyncActions.waitForSuitablePeers(EMPTY_SYNC_STATE)).isCompleted();
assertThat(fastSyncActions.waitForSuitablePeers(EMPTY_SYNC_STATE))
.isCompletedWithValue(EMPTY_SYNC_STATE);
}

@Test
Expand All @@ -111,7 +112,7 @@ public void waitForPeersShouldContinueWaitingUntilAtLeastOnePeerIsAvailable() {
assertThat(result).isNotCompleted();

EthProtocolManagerTestUtil.createPeer(ethProtocolManager);
assertThat(result).isCompleted();
assertThat(result).isCompletedWithValue(EMPTY_SYNC_STATE);
}

@Test
Expand Down

0 comments on commit dbd4467

Please sign in to comment.