Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

stop using goprocess to control teardown #278

Merged
merged 3 commits into from
Sep 8, 2021
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
63 changes: 24 additions & 39 deletions dial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import (
"testing"
"time"

addrutil "github.com/libp2p/go-addr-util"
. "github.com/libp2p/go-libp2p-swarm"

addrutil "github.com/libp2p/go-addr-util"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/peerstore"
"github.com/libp2p/go-libp2p-core/transport"

testutil "github.com/libp2p/go-libp2p-core/test"
"github.com/libp2p/go-libp2p-core/transport"
swarmt "github.com/libp2p/go-libp2p-swarm/testing"
"github.com/libp2p/go-libp2p-testing/ci"

ma "github.com/multiformats/go-multiaddr"
manet "github.com/multiformats/go-multiaddr/net"

. "github.com/libp2p/go-libp2p-swarm"
"github.com/stretchr/testify/require"
)

func init() {
Expand All @@ -36,50 +36,37 @@ func closeSwarms(swarms []*Swarm) {

func TestBasicDialPeer(t *testing.T) {
t.Parallel()
ctx := context.Background()

swarms := makeSwarms(ctx, t, 2)
swarms := makeSwarms(t, 2)
defer closeSwarms(swarms)
s1 := swarms[0]
s2 := swarms[1]

s1.Peerstore().AddAddrs(s2.LocalPeer(), s2.ListenAddresses(), peerstore.PermanentAddrTTL)

c, err := s1.DialPeer(ctx, s2.LocalPeer())
if err != nil {
t.Fatal(err)
}

s, err := c.NewStream(ctx)
if err != nil {
t.Fatal(err)
}
c, err := s1.DialPeer(context.Background(), s2.LocalPeer())
require.NoError(t, err)

s, err := c.NewStream(context.Background())
require.NoError(t, err)
s.Close()
}

func TestDialWithNoListeners(t *testing.T) {
t.Parallel()
ctx := context.Background()

s1 := makeDialOnlySwarm(ctx, t)

swarms := makeSwarms(ctx, t, 1)
s1 := makeDialOnlySwarm(t)
swarms := makeSwarms(t, 1)
defer closeSwarms(swarms)
s2 := swarms[0]

s1.Peerstore().AddAddrs(s2.LocalPeer(), s2.ListenAddresses(), peerstore.PermanentAddrTTL)

c, err := s1.DialPeer(ctx, s2.LocalPeer())
if err != nil {
t.Fatal(err)
}

s, err := c.NewStream(ctx)
if err != nil {
t.Fatal(err)
}
c, err := s1.DialPeer(context.Background(), s2.LocalPeer())
require.NoError(t, err)

s, err := c.NewStream(context.Background())
require.NoError(t, err)
s.Close()
}

Expand All @@ -104,7 +91,7 @@ func TestSimultDials(t *testing.T) {
t.Parallel()

ctx := context.Background()
swarms := makeSwarms(ctx, t, 2, swarmt.OptDisableReuseport)
swarms := makeSwarms(t, 2, swarmt.OptDisableReuseport)

// connect everyone
{
Expand Down Expand Up @@ -175,7 +162,7 @@ func TestDialWait(t *testing.T) {
t.Parallel()

ctx := context.Background()
swarms := makeSwarms(ctx, t, 1)
swarms := makeSwarms(t, 1)
s1 := swarms[0]
defer s1.Close()

Expand Down Expand Up @@ -215,7 +202,7 @@ func TestDialBackoff(t *testing.T) {
t.Parallel()

ctx := context.Background()
swarms := makeSwarms(ctx, t, 2)
swarms := makeSwarms(t, 2)
s1 := swarms[0]
s2 := swarms[1]
defer s1.Close()
Expand Down Expand Up @@ -422,7 +409,7 @@ func TestDialBackoffClears(t *testing.T) {
t.Parallel()

ctx := context.Background()
swarms := makeSwarms(ctx, t, 2)
swarms := makeSwarms(t, 2)
s1 := swarms[0]
s2 := swarms[1]
defer s1.Close()
Expand Down Expand Up @@ -491,7 +478,7 @@ func TestDialPeerFailed(t *testing.T) {
t.Parallel()
ctx := context.Background()

swarms := makeSwarms(ctx, t, 2)
swarms := makeSwarms(t, 2)
defer closeSwarms(swarms)
testedSwarm, targetSwarm := swarms[0], swarms[1]

Expand Down Expand Up @@ -530,7 +517,7 @@ func TestDialPeerFailed(t *testing.T) {
func TestDialExistingConnection(t *testing.T) {
ctx := context.Background()

swarms := makeSwarms(ctx, t, 2)
swarms := makeSwarms(t, 2)
defer closeSwarms(swarms)
s1 := swarms[0]
s2 := swarms[1]
Expand Down Expand Up @@ -574,7 +561,7 @@ func TestDialSimultaneousJoin(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

swarms := makeSwarms(ctx, t, 2)
swarms := makeSwarms(t, 2)
s1 := swarms[0]
s2 := swarms[1]
defer s1.Close()
Expand Down Expand Up @@ -676,12 +663,10 @@ func TestDialSelf(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

swarms := makeSwarms(ctx, t, 2)
swarms := makeSwarms(t, 2)
s1 := swarms[0]
defer s1.Close()

_, err := s1.DialPeer(ctx, s1.LocalPeer())
if err != ErrDialToSelf {
t.Fatal("expected error from self dial")
}
require.ErrorIs(t, err, ErrDialToSelf, "expected error from self dial")
}
11 changes: 5 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ go 1.16

require (
github.com/ipfs/go-log v1.0.5
github.com/jbenet/goprocess v0.1.4
github.com/libp2p/go-addr-util v0.1.0
github.com/libp2p/go-conn-security-multistream v0.2.1
github.com/libp2p/go-libp2p-core v0.9.1-0.20210824123029-094b0d3f8ba2
github.com/libp2p/go-conn-security-multistream v0.3.0
github.com/libp2p/go-libp2p-core v0.10.0
github.com/libp2p/go-libp2p-peerstore v0.2.8
github.com/libp2p/go-libp2p-quic-transport v0.11.2
github.com/libp2p/go-libp2p-testing v0.4.2
github.com/libp2p/go-libp2p-transport-upgrader v0.4.6
github.com/libp2p/go-libp2p-quic-transport v0.13.0
github.com/libp2p/go-libp2p-testing v0.5.0
github.com/libp2p/go-libp2p-transport-upgrader v0.5.0
github.com/libp2p/go-libp2p-yamux v0.5.0
github.com/libp2p/go-maddr-filter v0.1.0
github.com/libp2p/go-stream-muxer-multistream v0.3.0
Expand Down
Loading