Skip to content

Commit

Permalink
Merge pull request #1268 from libp2p/reconnect-on-quic
Browse files Browse the repository at this point in the history
run reconnect test using QUIC
  • Loading branch information
marten-seemann committed Dec 18, 2021
2 parents e014b96 + c17d397 commit 9bb973c
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions p2p/test/reconnects/reconnect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import (
"testing"
"time"

"github.com/stretchr/testify/require"
bhost "github.com/libp2p/go-libp2p/p2p/host/basic"

u "github.com/ipfs/go-ipfs-util"
logging "github.com/ipfs/go-log/v2"
"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/protocol"

swarmt "github.com/libp2p/go-libp2p-swarm/testing"
bhost "github.com/libp2p/go-libp2p/p2p/host/basic"

u "github.com/ipfs/go-ipfs-util"
logging "github.com/ipfs/go-log/v2"
"github.com/stretchr/testify/require"
)

var log = logging.Logger("reconnect")
Expand Down Expand Up @@ -102,9 +104,11 @@ func newSender() (chan sendChans, func(s network.Stream)) {

// TestReconnect tests whether hosts are able to disconnect and reconnect.
func TestReconnect2(t *testing.T) {
h1, err := bhost.NewHost(swarmt.GenSwarm(t), nil)
// TCP RST handling is flaky in OSX, see https://github.com/golang/go/issues/50254.
// We can avoid this by using QUIC in this test.
h1, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableTCP), nil)
require.NoError(t, err)
h2, err := bhost.NewHost(swarmt.GenSwarm(t), nil)
h2, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableTCP), nil)
require.NoError(t, err)
hosts := []host.Host{h1, h2}

Expand All @@ -117,7 +121,7 @@ func TestReconnect2(t *testing.T) {
}
for i := 0; i < rounds; i++ {
log.Debugf("TestReconnect: %d/%d\n", i, rounds)
SubtestConnSendDisc(t, hosts)
subtestConnSendDisc(t, hosts)
}
}

Expand All @@ -126,7 +130,9 @@ func TestReconnect5(t *testing.T) {
const num = 5
hosts := make([]host.Host, 0, num)
for i := 0; i < num; i++ {
h, err := bhost.NewHost(swarmt.GenSwarm(t), nil)
// TCP RST handling is flaky in OSX, see https://github.com/golang/go/issues/50254.
// We can avoid this by using QUIC in this test.
h, err := bhost.NewHost(swarmt.GenSwarm(t, swarmt.OptDisableTCP), nil)
require.NoError(t, err)
h.SetStreamHandler(protocol.TestingID, EchoStreamHandler)
hosts = append(hosts, h)
Expand All @@ -138,12 +144,11 @@ func TestReconnect5(t *testing.T) {
}
for i := 0; i < rounds; i++ {
log.Debugf("TestReconnect: %d/%d\n", i, rounds)
SubtestConnSendDisc(t, hosts)
subtestConnSendDisc(t, hosts)
}
}

func SubtestConnSendDisc(t *testing.T, hosts []host.Host) {

func subtestConnSendDisc(t *testing.T, hosts []host.Host) {
ctx := context.Background()
numStreams := 3 * len(hosts)
numMsgs := 10
Expand Down

0 comments on commit 9bb973c

Please sign in to comment.