p2p: tighten up and test PeerManager (#6034)

This tightens up the `PeerManager` and related code, adds a ton of tests, and fixes a bunch of inconsistencies and bugs.
This commit is contained in:
Erik Grinaker
2021-02-03 06:15:23 +00:00
committed by GitHub
parent fd597dc726
commit 2aad26e2f1
21 changed files with 3066 additions and 1281 deletions
+6 -7
View File
@@ -115,9 +115,9 @@ func TestRouter(t *testing.T) {
// Wait for peers to come online, and ping them as they do.
for i := 0; i < len(peers); i++ {
peerUpdate := <-peerUpdates.Updates()
peerID := peerUpdate.PeerID
peerID := peerUpdate.NodeID
require.Equal(t, p2p.PeerUpdate{
PeerID: peerID,
NodeID: peerID,
Status: p2p.PeerStatusUp,
}, peerUpdate)
@@ -140,13 +140,12 @@ func TestRouter(t *testing.T) {
// We then submit an error for a peer, and watch it get disconnected.
channel.Error() <- p2p.PeerError{
PeerID: peers[0].NodeID,
Err: errors.New("test error"),
Severity: p2p.PeerErrorSeverityCritical,
NodeID: peers[0].NodeID,
Err: errors.New("test error"),
}
peerUpdate := <-peerUpdates.Updates()
require.Equal(t, p2p.PeerUpdate{
PeerID: peers[0].NodeID,
NodeID: peers[0].NodeID,
Status: p2p.PeerStatusDown,
}, peerUpdate)
@@ -154,7 +153,7 @@ func TestRouter(t *testing.T) {
// for that to happen.
peerUpdate = <-peerUpdates.Updates()
require.Equal(t, p2p.PeerUpdate{
PeerID: peers[0].NodeID,
NodeID: peers[0].NodeID,
Status: p2p.PeerStatusUp,
}, peerUpdate)
}