Skip to content

Commit

Permalink
tests: fix a race in TestP2PwsStreamHandlerDedup (#6116)
Browse files Browse the repository at this point in the history
  • Loading branch information
algorandskiy authored Aug 29, 2024
1 parent f6c59a4 commit 10e8b39
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 39 deletions.
37 changes: 0 additions & 37 deletions network/p2p/capabilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"testing"
"time"

golog "github.com/ipfs/go-log"
"github.com/libp2p/go-libp2p"
dht "github.com/libp2p/go-libp2p-kad-dht"
"github.com/libp2p/go-libp2p/core/discovery"
Expand All @@ -38,42 +37,6 @@ import (
"github.com/algorand/go-algorand/test/partitiontest"
)

func TestCapabilities_Discovery(t *testing.T) {
partitiontest.PartitionTest(t)

golog.SetDebugLogging()
var caps []*CapabilitiesDiscovery
var addrs []peer.AddrInfo
testSize := 3
for i := 0; i < testSize; i++ {
tempdir := t.TempDir()
ps, err := peerstore.NewPeerStore(nil, "")
require.NoError(t, err)
h, _, err := MakeHost(config.GetDefaultLocal(), tempdir, ps)
require.NoError(t, err)
capD, err := MakeCapabilitiesDiscovery(context.Background(), config.GetDefaultLocal(), h, "devtestnet", logging.Base(), func() []peer.AddrInfo { return nil })
require.NoError(t, err)
caps = append(caps, capD)
addrs = append(addrs, peer.AddrInfo{
ID: capD.Host().ID(),
Addrs: capD.Host().Addrs(),
})
}
for _, capD := range caps {
peersAdded := 0
for _, addr := range addrs {
added, err := capD.addPeer(addr)
require.NoError(t, err)
require.True(t, added)
peersAdded++
}
err := capD.dht.Bootstrap(context.Background())
require.NoError(t, err)
capD.dht.ForceRefresh()
require.Equal(t, peersAdded, capD.dht.RoutingTable().Size())
}
}

func setupDHTHosts(t *testing.T, numHosts int) []*dht.IpfsDHT {
var hosts []host.Host
var bootstrapPeers []peer.AddrInfo
Expand Down
6 changes: 4 additions & 2 deletions network/p2pNetwork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1187,8 +1187,10 @@ func TestP2PwsStreamHandlerDedup(t *testing.T) {
return networkPeerIdentityDisconnect.GetUint64Value() == networkPeerIdentityDisconnectInitial+1
}, 2*time.Second, 50*time.Millisecond)

require.False(t, netA.hasPeers())
require.False(t, netB.hasPeers())
// now allow the peer made outgoing connection to handle conn closing initiated by the other side
require.Eventually(t, func() bool {
return !netA.hasPeers() && !netB.hasPeers()
}, 2*time.Second, 50*time.Millisecond)
}

// TestP2PEnableGossipService_NodeDisable ensures that a node with EnableGossipService=false
Expand Down

0 comments on commit 10e8b39

Please sign in to comment.