Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Attempt to fix intermittency in FullSyncDownloaderTest #830

Merged
merged 3 commits into from
Feb 11, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,12 @@ public void syncsToBetterChain_multipleSegments() {
final FullSyncDownloader<?> downloader = downloader(syncConfig);
downloader.start();

while (!syncState.syncTarget().isPresent()) {
peer.respond(responder);
}
peer.respondWhileOtherThreadsWork(responder, () -> !syncState.syncTarget().isPresent());
assertThat(syncState.syncTarget()).isPresent();
assertThat(syncState.syncTarget().get().peer()).isEqualTo(peer.getEthPeer());

while (localBlockchain.getChainHeadBlockNumber() < targetBlock) {
peer.respond(responder);
}
peer.respondWhileOtherThreadsWork(
responder, () -> localBlockchain.getChainHeadBlockNumber() < targetBlock);

assertThat(localBlockchain.getChainHeadBlockNumber()).isEqualTo(targetBlock);
}
Expand All @@ -157,15 +154,12 @@ public void syncsToBetterChain_singleSegment() {
final FullSyncDownloader<?> downloader = downloader(syncConfig);
downloader.start();

while (!syncState.syncTarget().isPresent()) {
peer.respond(responder);
}
peer.respondWhileOtherThreadsWork(responder, () -> !syncState.syncTarget().isPresent());
assertThat(syncState.syncTarget()).isPresent();
assertThat(syncState.syncTarget().get().peer()).isEqualTo(peer.getEthPeer());

while (localBlockchain.getChainHeadBlockNumber() < targetBlock) {
peer.respond(responder);
}
peer.respondWhileOtherThreadsWork(
responder, () -> localBlockchain.getChainHeadBlockNumber() < targetBlock);

assertThat(localBlockchain.getChainHeadBlockNumber()).isEqualTo(targetBlock);
}
Expand All @@ -189,15 +183,12 @@ public void syncsToBetterChain_singleSegmentOnBoundary() {
final FullSyncDownloader<?> downloader = downloader(syncConfig);
downloader.start();

while (!syncState.syncTarget().isPresent()) {
peer.respond(responder);
}
peer.respondWhileOtherThreadsWork(responder, () -> !syncState.syncTarget().isPresent());
assertThat(syncState.syncTarget()).isPresent();
assertThat(syncState.syncTarget().get().peer()).isEqualTo(peer.getEthPeer());

while (localBlockchain.getChainHeadBlockNumber() < targetBlock) {
peer.respond(responder);
}
peer.respondWhileOtherThreadsWork(
responder, () -> localBlockchain.getChainHeadBlockNumber() < targetBlock);

assertThat(localBlockchain.getChainHeadBlockNumber()).isEqualTo(targetBlock);
}
Expand All @@ -219,9 +210,7 @@ public void doesNotSyncToWorseChain() {
peer.respond(responder);
assertThat(syncState.syncTarget()).isNotPresent();

while (peer.hasOutstandingRequests()) {
peer.respond(responder);
}
peer.respondWhileOtherThreadsWork(responder, peer::hasOutstandingRequests);

assertThat(syncState.syncTarget()).isNotPresent();
verify(localBlockchain, times(0)).appendBlock(any(), any());
Expand Down Expand Up @@ -256,9 +245,8 @@ public void syncsToBetterChain_fromFork() {
final FullSyncDownloader<?> downloader = downloader(syncConfig);
downloader.start();

while (localBlockchain.getChainHeadBlockNumber() < targetBlock) {
peer.respond(responder);
}
peer.respondWhileOtherThreadsWork(
responder, () -> localBlockchain.getChainHeadBlockNumber() < targetBlock);

assertThat(syncState.syncTarget()).isPresent();
assertThat(syncState.syncTarget().get().peer()).isEqualTo(peer.getEthPeer());
Expand Down Expand Up @@ -330,9 +318,7 @@ public void switchesSyncTarget_betterHeight() {
downloader.start();

// Process until the sync target is selected
while (!syncState.syncTarget().isPresent()) {
peerA.respond(responder);
}
peerA.respondWhileOtherThreadsWork(responder, () -> !syncState.syncTarget().isPresent());
assertThat(syncState.syncTarget()).isPresent();
assertThat(syncState.syncTarget().get().peer()).isEqualTo(peerA.getEthPeer());

Expand Down Expand Up @@ -370,9 +356,7 @@ public void doesNotSwitchSyncTarget_betterHeightUnderThreshold() {
downloader.start();

// Process until the sync target is selected
while (!syncState.syncTarget().isPresent()) {
bestPeer.respond(responder);
}
bestPeer.respondWhileOtherThreadsWork(responder, () -> !syncState.syncTarget().isPresent());
assertThat(syncState.syncTarget()).isPresent();
assertThat(syncState.syncTarget().get().peer()).isEqualTo(bestPeer.getEthPeer());

Expand Down Expand Up @@ -410,9 +394,7 @@ public void switchesSyncTarget_betterTd() {
downloader.start();

// Process until the sync target is selected
while (!syncState.syncTarget().isPresent()) {
peerA.respond(responder);
}
peerA.respondWhileOtherThreadsWork(responder, () -> !syncState.syncTarget().isPresent());
assertThat(syncState.syncTarget()).isPresent();
assertThat(syncState.syncTarget().get().peer()).isEqualTo(peerA.getEthPeer());

Expand Down Expand Up @@ -457,9 +439,7 @@ public void doesNotSwitchSyncTarget_betterTdUnderThreshold() {
downloader.start();

// Process until the sync target is selected
while (!syncState.syncTarget().isPresent()) {
bestPeer.respond(responder);
}
bestPeer.respondWhileOtherThreadsWork(responder, () -> !syncState.syncTarget().isPresent());
assertThat(syncState.syncTarget()).isPresent();
assertThat(syncState.syncTarget().get().peer()).isEqualTo(bestPeer.getEthPeer());

Expand Down Expand Up @@ -512,13 +492,7 @@ public void recoversFromSyncTargetDisconnect() {
downloader.start();

// Process through sync target selection
await()
.atMost(10, TimeUnit.SECONDS)
.untilAsserted(
() -> {
bestPeer.respond(bestResponder);
assertThat(syncState.syncTarget()).isNotEmpty();
});
bestPeer.respondWhileOtherThreadsWork(bestResponder, () -> !syncState.syncTarget().isPresent());

assertThat(syncState.syncTarget()).isPresent();
assertThat(syncState.syncTarget().get().peer()).isEqualTo(bestPeer.getEthPeer());
Expand All @@ -534,6 +508,7 @@ public void recoversFromSyncTargetDisconnect() {
// Process through the first import
await()
.atMost(10, TimeUnit.SECONDS)
.pollInterval(100, TimeUnit.MILLISECONDS)
.untilAsserted(
() -> {
if (!bestPeer.respond(bestResponder)) {
Expand All @@ -543,20 +518,20 @@ public void recoversFromSyncTargetDisconnect() {
.isNotEqualTo(localChainHeadAtStart);
});

// Sanity check that we haven't already passed the second best peer
assertThat(localBlockchain.getChainHeadBlockNumber()).isLessThan(secondBestPeerChainHead);

// Disconnect peer
ethProtocolManager.handleDisconnect(
bestPeer.getPeerConnection(), DisconnectReason.TOO_MANY_PEERS, true);

// Downloader should recover and sync to next best peer, but it may stall
// for 10 seconds first (by design).
await()
.atMost(30, TimeUnit.SECONDS)
.untilAsserted(
() -> {
secondBestPeer.respond(secondBestResponder);
assertThat(localBlockchain.getChainHeadBlockNumber())
.isEqualTo(secondBestPeerChainHead);
});
secondBestPeer.respondWhileOtherThreadsWork(
secondBestResponder,
() -> localBlockchain.getChainHeadBlockNumber() != secondBestPeerChainHead);

assertThat(localBlockchain.getChainHeadBlockNumber()).isEqualTo(secondBestPeerChainHead);
}

@Test
Expand Down