@@ -128,6 +128,7 @@ class PeerManagerSpec
128
128
start()
129
129
handleInitialNodesDiscovery()
130
130
131
+ // There are 2 bootstrap nodes in the test config.
131
132
createdPeers.head.probe.expectMsgClass(classOf [PeerActor .ConnectTo ])
132
133
createdPeers(1 ).probe.expectMsgClass(classOf [PeerActor .ConnectTo ])
133
134
@@ -140,20 +141,23 @@ class PeerManagerSpec
140
141
141
142
peerManager ! PeerManagerActor .HandlePeerConnection (incomingConnection1.ref, incomingPeerAddress1)
142
143
144
+ // It should have created the next peer for the first incoming connection (probably using a synchronous test scheduler).
143
145
val probe2 : TestProbe = createdPeers(2 ).probe
144
146
val peer = Peer (incomingPeerAddress1, probe2.ref, incomingConnection = true , Some (incomingNodeId1))
145
-
146
147
probe2.expectMsg(PeerActor .HandleConnection (incomingConnection1.ref, incomingPeerAddress1))
147
148
probe2.reply(PeerEvent .PeerHandshakeSuccessful (peer, initialPeerInfo))
148
149
149
150
val watcher = TestProbe ()
150
151
watcher.watch(incomingConnection3.ref)
151
152
153
+ // Try to connect with 2 more.
152
154
peerManager ! PeerManagerActor .HandlePeerConnection (incomingConnection2.ref, incomingPeerAddress2)
153
155
peerManager ! PeerManagerActor .HandlePeerConnection (incomingConnection3.ref, incomingPeerAddress3)
154
156
157
+ // The second should be terminated because max-pending is 1.
155
158
watcher.expectMsgClass(classOf [Terminated ])
156
159
160
+ // Simulate the successful handshake with the 2nd incoming. It should be disconnected because max-incoming is 1.
157
161
val probe3 : TestProbe = createdPeers(3 ).probe
158
162
159
163
val secondPeer = Peer (incomingPeerAddress2, probe3.ref, incomingConnection = true , Some (incomingNodeId2))
@@ -166,6 +170,14 @@ class PeerManagerSpec
166
170
probe3.ref ! PoisonPill
167
171
168
172
peerEventBus.expectMsg(Publish (PeerDisconnected (PeerId (probe3.ref.path.name))))
173
+
174
+ // TooManyPeers should also trigger a pruning cycle.
175
+ peerStatistics.expectMsg(
176
+ PeerStatisticsActor .GetStatsForAll (peerConfiguration.statSlotDuration * peerConfiguration.statSlotCount)
177
+ )
178
+ peerStatistics.reply(PeerStatisticsActor .StatsForAll (Map .empty))
179
+ // There's only one connection that can be pruned.
180
+ probe2.expectMsg(PeerActor .DisconnectPeer (Disconnect .Reasons .TooManyPeers ))
169
181
}
170
182
171
183
it should " handle common message about getting peers" in new TestSetup {
0 commit comments