Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: fix a race in TestP2PwsStreamHandlerDedup #6116

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading