Search in sources :

Example 1 with StubPeer

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);
}
Also used : StubPeer(tech.pegasys.teku.network.p2p.peer.StubPeer) Test(org.junit.jupiter.api.Test)

Example 2 with StubPeer

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);
}
Also used : StubPeer(tech.pegasys.teku.network.p2p.peer.StubPeer) Test(org.junit.jupiter.api.Test)

Example 3 with StubPeer

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);
}
Also used : StubPeer(tech.pegasys.teku.network.p2p.peer.StubPeer) Test(org.junit.jupiter.api.Test)

Example 4 with StubPeer

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);
}
Also used : StubPeer(tech.pegasys.teku.network.p2p.peer.StubPeer) Test(org.junit.jupiter.api.Test)

Example 5 with StubPeer

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);
}
Also used : MockNodeId(tech.pegasys.teku.networking.p2p.mock.MockNodeId) StubPeer(tech.pegasys.teku.network.p2p.peer.StubPeer) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)18 StubPeer (tech.pegasys.teku.network.p2p.peer.StubPeer)18 MockNodeId (tech.pegasys.teku.networking.p2p.mock.MockNodeId)14 ConnectionManager (tech.pegasys.teku.networking.p2p.connection.ConnectionManager)9 Peer (tech.pegasys.teku.networking.p2p.peer.Peer)3 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)2 PeerAddress (tech.pegasys.teku.networking.p2p.network.PeerAddress)1