Fixup itest net tests

This commit is contained in:
Aayush 2022-06-23 14:02:10 -04:00
parent 49f074144d
commit 9662c1463d
4 changed files with 73 additions and 37 deletions

View File

@ -768,11 +768,6 @@ workflows:
suite: itest-api
target: "./itests/api_test.go"
- test:
name: test-itest-net
suite: itest-net
target: "./itests/net_test.go"
- test:
name: test-itest-batch_deal
suite: itest-batch_deal
@ -893,6 +888,11 @@ workflows:
suite: itest-multisig
target: "./itests/multisig_test.go"
- test:
name: test-itest-net
suite: itest-net
target: "./itests/net_test.go"
- test:
name: test-itest-nonce
suite: itest-nonce

View File

@ -8,6 +8,7 @@ import (
"time"
logging "github.com/ipfs/go-log/v2"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/stretchr/testify/require"
"github.com/filecoin-project/go-address"
@ -98,11 +99,21 @@ func (ts *apiSuite) testConnectTwo(t *testing.T) {
peers, err := one.NetPeers(ctx)
require.NoError(t, err)
require.Lenf(t, peers, 2, "node one doesn't have 2 peers")
countPeerIDs := func(peers []peer.AddrInfo) int {
peerIDs := make(map[peer.ID]struct{})
for _, p := range peers {
peerIDs[p.ID] = struct{}{}
}
return len(peerIDs)
}
require.Equal(t, countPeerIDs(peers), 2, "node one doesn't have 2 peers")
peers, err = two.NetPeers(ctx)
require.NoError(t, err)
require.Lenf(t, peers, 2, "node two doesn't have 2 peers")
require.Equal(t, countPeerIDs(peers), 2, "node one doesn't have 2 peers")
}
func (ts *apiSuite) testSearchMsg(t *testing.T) {

View File

@ -340,7 +340,7 @@ func (n *Ensemble) Start() *Ensemble {
node.FullAPI(&full.FullNode, node.Lite(full.options.lite)),
node.Base(),
node.Repo(r),
node.MockHost(n.mn),
node.If(full.options.disableLibp2p, node.MockHost(n.mn)),
node.Test(),
// so that we subscribe to pubsub topics immediately
@ -583,7 +583,7 @@ func (n *Ensemble) Start() *Ensemble {
node.Repo(r),
node.Test(),
node.If(!m.options.disableLibp2p, node.MockHost(n.mn)),
node.If(m.options.disableLibp2p, node.MockHost(n.mn)),
node.Override(new(v1api.FullNode), m.FullNode.FullNode),
node.Override(new(*lotusminer.Miner), lotusminer.NewTestMiner(mineBlock, m.ActorAddr)),

View File

@ -6,13 +6,14 @@ import (
"fmt"
"testing"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/itests/kit"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
manet "github.com/multiformats/go-multiaddr/net"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/itests/kit"
)
func TestNetConn(t *testing.T) {
@ -52,18 +53,6 @@ func TestNetConn(t *testing.T) {
t.Errorf("agents not matching. %s", err.Error())
}
//stm: @NETWORK_COMMON_BANDWIDTH_STATS_001
bandwidth, err := secondNode.NetBandwidthStats(ctx)
require.NoError(t, err)
//stm: @NETWORK_COMMON_BANDWIDTH_STATS_BY_PEER_001
peerBandwidths, err := firstNode.NetBandwidthStatsByPeer(ctx)
require.NoError(t, err)
if peerBandwidths[secondNodeID.String()] != bandwidth {
t.Errorf("bandwidths differ")
}
//stm: @NETWORK_COMMON_FIND_PEER_001
secondNodePeer, err := firstNode.NetFindPeer(ctx, secondNodeID)
require.NoError(t, err)
@ -81,10 +70,7 @@ func TestNetConn(t *testing.T) {
//stm: @NETWORK_COMMON_PEERS_001
addrs, err := firstNode.NetPeers(ctx)
require.NoError(t, err)
if len(addrs) > 0 {
t.Errorf("connected peer does not exist in network")
}
require.NotEqual(t, 0, len(addrs))
//stm: @NETWORK_COMMON_DISCONNECT_001
err = firstNode.NetDisconnect(ctx, secondNodeID)
@ -170,13 +156,20 @@ func TestNetLimit(t *testing.T) {
func TestNetBlockPeer(t *testing.T) {
ctx := context.Background()
firstNode, secondNode, _, ens := kit.EnsembleTwoOne(t)
ens.InterconnectAll()
firstNode, secondNode, _, _ := kit.EnsembleTwoOne(t)
//stm: @NETWORK_COMMON_ID_001
firstAddrInfo, _ := firstNode.NetAddrsListen(ctx)
firstNodeID, err := firstNode.ID(ctx)
require.NoError(t, err)
secondNodeID, err := secondNode.ID(ctx)
require.NoError(t, err)
// Sanity check that we're not already connected somehow
connectedness, err := secondNode.NetConnectedness(ctx, firstNodeID)
require.NoError(t, err, "failed to determine connectedness")
require.NotEqual(t, connectedness, network.Connected, "shouldn't already be connected")
//stm: @NETWORK_COMMON_BLOCK_ADD_001
err = firstNode.NetBlockAdd(ctx, api.NetBlockList{Peers: []peer.ID{secondNodeID}})
require.NoError(t, err)
@ -189,6 +182,11 @@ func TestNetBlockPeer(t *testing.T) {
t.Errorf("blocked peer not in blocked peer list")
}
require.Error(t, secondNode.NetConnect(ctx, firstAddrInfo), "shouldn't be able to connect to second node")
connectedness, err = secondNode.NetConnectedness(ctx, firstAddrInfo.ID)
require.NoError(t, err, "failed to determine connectedness")
require.NotEqual(t, connectedness, network.Connected)
//stm: @NETWORK_COMMON_BLOCK_REMOVE_001
err = firstNode.NetBlockRemove(ctx, api.NetBlockList{Peers: []peer.ID{secondNodeID}})
require.NoError(t, err)
@ -201,20 +199,24 @@ func TestNetBlockPeer(t *testing.T) {
t.Errorf("failed to remove blocked peer from blocked peer list")
}
require.NoError(t, secondNode.NetConnect(ctx, firstAddrInfo), "failed to connect to second node")
connectedness, err = secondNode.NetConnectedness(ctx, firstAddrInfo.ID)
require.NoError(t, err, "failed to determine connectedness")
require.Equal(t, connectedness, network.Connected)
}
func TestNetBlockIPAddr(t *testing.T) {
ctx := context.Background()
firstNode, secondNode, _, ens := kit.EnsembleTwoOne(t)
ens.InterconnectAll()
firstNode, secondNode, _, _ := kit.EnsembleTwoOne(t)
//stm: @NETWORK_COMMON_ADDRS_LISTEN_001
addrInfo, _ := secondNode.NetAddrsListen(ctx)
firstAddrInfo, _ := firstNode.NetAddrsListen(ctx)
secondAddrInfo, _ := secondNode.NetAddrsListen(ctx)
var secondNodeIPs []string
for _, addr := range addrInfo.Addrs {
for _, addr := range secondAddrInfo.Addrs {
ip, err := manet.ToIP(addr)
if err != nil {
continue
@ -222,17 +224,36 @@ func TestNetBlockIPAddr(t *testing.T) {
secondNodeIPs = append(secondNodeIPs, ip.String())
}
// Sanity check that we're not already connected somehow
connectedness, err := secondNode.NetConnectedness(ctx, firstAddrInfo.ID)
require.NoError(t, err, "failed to determine connectedness")
require.NotEqual(t, connectedness, network.Connected, "shouldn't already be connected")
//stm: @NETWORK_COMMON_BLOCK_ADD_001
err := firstNode.NetBlockAdd(ctx, api.NetBlockList{IPAddrs: secondNodeIPs})
require.NoError(t, err)
require.NoError(t, firstNode.NetBlockAdd(ctx, api.NetBlockList{
IPAddrs: secondNodeIPs}), "failed to add blocked IPs")
//stm: @NETWORK_COMMON_BLOCK_LIST_001
list, err := firstNode.NetBlockList(ctx)
require.NoError(t, err)
if len(list.IPAddrs) == 0 || list.IPAddrs[0] != secondNodeIPs[0] {
t.Errorf("blocked ip not in blocked ip list")
require.Equal(t, len(list.IPAddrs), len(secondNodeIPs), "expected %d blocked IPs", len(secondNodeIPs))
for _, blockedIP := range list.IPAddrs {
found := false
for _, secondNodeIP := range secondNodeIPs {
if blockedIP == secondNodeIP {
found = true
break
}
}
require.True(t, found, "blocked IP %s is not one of secondNodeIPs", blockedIP)
}
require.Error(t, secondNode.NetConnect(ctx, firstAddrInfo), "shouldn't be able to connect to second node")
connectedness, err = secondNode.NetConnectedness(ctx, firstAddrInfo.ID)
require.NoError(t, err, "failed to determine connectedness")
require.NotEqual(t, connectedness, network.Connected)
//stm: @NETWORK_COMMON_BLOCK_REMOVE_001
err = firstNode.NetBlockRemove(ctx, api.NetBlockList{IPAddrs: secondNodeIPs})
@ -246,6 +267,10 @@ func TestNetBlockIPAddr(t *testing.T) {
t.Errorf("failed to remove blocked ip from blocked ip list")
}
require.NoError(t, secondNode.NetConnect(ctx, firstAddrInfo), "failed to connect to second node")
connectedness, err = secondNode.NetConnectedness(ctx, firstAddrInfo.ID)
require.NoError(t, err, "failed to determine connectedness")
require.Equal(t, connectedness, network.Connected)
}
func getConnState(ctx context.Context, t *testing.T, node *kit.TestFullNode, peer peer.ID) network.Connectedness {