prysm-pulse/shared/p2p/monitoring_test.go
Preston Van Loon d1d2af4e50
Reconnect to VIP peers (#2070)
* reconnect to peers

* Add test for p2p
2019-03-25 10:36:44 -05:00

32 lines
731 B
Go

package p2p
import (
"context"
"testing"
bhost "github.com/libp2p/go-libp2p-blankhost"
pstore "github.com/libp2p/go-libp2p-peerstore"
swarmt "github.com/libp2p/go-libp2p-swarm/testing"
)
func TestEnsurePeerConnections_reconnectsToPeer(t *testing.T) {
ctx := context.Background()
h := bhost.NewBlankHost(swarmt.GenSwarm(t, ctx))
vipPeer := bhost.NewBlankHost(swarmt.GenSwarm(t, ctx))
vipMAddrs, err := pstore.InfoToP2pAddrs(&pstore.PeerInfo{ID: vipPeer.ID(), Addrs: vipPeer.Addrs()})
if err != nil {
t.Fatal(err)
}
if len(h.Peerstore().Peers()) != 1 {
t.Fatal("expected 1 peer")
}
ensurePeerConnections(ctx, h, vipMAddrs[0].String())
if len(h.Peerstore().Peers()) != 2 {
t.Fatal("expected 2 peers")
}
}