use of tech.pegasys.teku.network.p2p.peer.StubPeer in project teku by ConsenSys.
the class SyncStateTrackerTest method shouldLogCorrectSequenceOfSyncEvents.
@Test
public void shouldLogCorrectSequenceOfSyncEvents() {
// start syncing
syncSubscriber.onSyncingChange(true);
assertSyncState(SyncState.SYNCING);
verify(eventLogger).syncStart();
// get connected
when(network.getPeerCount()).thenReturn(STARTUP_TARGET_PEER_COUNT);
peerSubscriber.onConnected(new StubPeer());
// turn head optimistic
tracker.onOptimisticHeadChanged(true);
verify(eventLogger).headTurnedOptimisticWhileSyncing();
// beacon synced while head is optimistic
syncSubscriber.onSyncingChange(false);
verify(eventLogger).syncCompletedWhileHeadIsOptimistic();
// head no longer optimistic
tracker.onOptimisticHeadChanged(false);
assertSyncState(SyncState.IN_SYNC);
verify(eventLogger).syncCompleted();
verifyNoMoreInteractions(eventLogger);
}
use of tech.pegasys.teku.network.p2p.peer.StubPeer in project teku by ConsenSys.
the class SyncStateTrackerTest method shouldBeInSyncWhenTargetPeerCountReachedAndSyncNotStarted.
@Test
public void shouldBeInSyncWhenTargetPeerCountReachedAndSyncNotStarted() {
when(network.getPeerCount()).thenReturn(STARTUP_TARGET_PEER_COUNT);
peerSubscriber.onConnected(new StubPeer());
assertSyncState(SyncState.IN_SYNC);
verifyNoInteractions(eventLogger);
}
use of tech.pegasys.teku.network.p2p.peer.StubPeer in project teku by ConsenSys.
the class SyncStateTrackerTest method shouldBeInSyncWhenSyncCompletesIfPeerRequirementMet.
@Test
public void shouldBeInSyncWhenSyncCompletesIfPeerRequirementMet() {
syncSubscriber.onSyncingChange(true);
assertSyncState(SyncState.SYNCING);
when(network.getPeerCount()).thenReturn(STARTUP_TARGET_PEER_COUNT);
peerSubscriber.onConnected(new StubPeer());
syncSubscriber.onSyncingChange(false);
assertSyncState(SyncState.IN_SYNC);
}
use of tech.pegasys.teku.network.p2p.peer.StubPeer in project teku by ConsenSys.
the class SyncStateTrackerTest method shouldRemainInStartupUntilPeerCountIsReached.
@Test
public void shouldRemainInStartupUntilPeerCountIsReached() {
when(network.getPeerCount()).thenReturn(1);
peerSubscriber.onConnected(new StubPeer());
assertSyncState(SyncState.START_UP);
}
use of tech.pegasys.teku.network.p2p.peer.StubPeer in project teku by ConsenSys.
the class Eth2PeerSelectionStrategyTest method selectPeersToDisconnect_shouldDisconnectExcessRandomlySelectedPeersWhenOutscored.
@Test
void selectPeersToDisconnect_shouldDisconnectExcessRandomlySelectedPeersWhenOutscored() {
final Eth2PeerSelectionStrategy strategy = createStrategy(2, 2, 1);
final StubPeer peer1 = new StubPeer(new MockNodeId(1));
final StubPeer peer2 = new StubPeer(new MockNodeId(2));
final StubPeer peer3 = new StubPeer(new MockNodeId(3));
when(network.getPeerCount()).thenReturn(3);
when(network.streamPeers()).thenReturn(Stream.of(peer1, peer2, peer3));
peerPools.addPeerToPool(peer1.getId(), PeerPool.RANDOMLY_SELECTED);
peerPools.addPeerToPool(peer2.getId(), PeerPool.RANDOMLY_SELECTED);
peerScorer.setScore(peer1.getId(), 100);
peerScorer.setScore(peer2.getId(), 50);
peerScorer.setScore(peer3.getId(), 250);
withShuffleOrder(peer2, peer1, peer3);
// Peer2 was dropped from the random pool and had the worst score so got dropped
assertThat(strategy.selectPeersToDisconnect(network, peerPools)).containsExactlyInAnyOrder(peer2);
}
Aggregations