Skip to content
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
6 changes: 2 additions & 4 deletions libp2p_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,17 +550,15 @@ func TestWebRTCReuseAddrWithQUIC(t *testing.T) {
}

t.Run("quic client can connect", func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()
p := ping.NewPingService(quicClient)
resCh := p.Ping(ctx, h1.ID())
res := <-resCh
require.NoError(t, res.Error)
})

t.Run("webrtc client can connect", func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()
p := ping.NewPingService(webrtcClient)
resCh := p.Ping(ctx, h1.ID())
res := <-resCh
Expand Down
12 changes: 4 additions & 8 deletions p2p/discovery/backoff/backoffcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ func withClock(c clock) BackoffDiscoveryOption {
}

func TestBackoffDiscoverySingleBackoff(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

clock := mockClock.NewMock()
discServer := mocks.NewDiscoveryServer(clock)
Expand Down Expand Up @@ -137,8 +136,7 @@ func TestBackoffDiscoverySingleBackoff(t *testing.T) {

func TestBackoffDiscoveryMultipleBackoff(t *testing.T) {
clock := mockClock.NewMock()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

discServer := mocks.NewDiscoveryServer(clock)

Expand Down Expand Up @@ -195,8 +193,7 @@ func TestBackoffDiscoveryMultipleBackoff(t *testing.T) {
}

func TestBackoffDiscoverySimultaneousQuery(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

clock := mockClock.NewMock()
discServer := mocks.NewDiscoveryServer(clock)
Expand Down Expand Up @@ -257,8 +254,7 @@ func TestBackoffDiscoverySimultaneousQuery(t *testing.T) {
}

func TestBackoffDiscoveryCacheCapacity(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

clock := mockClock.NewMock()
discServer := mocks.NewDiscoveryServer(clock)
Expand Down
6 changes: 2 additions & 4 deletions p2p/discovery/routing/routing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ func (m *mockRouting) FindProvidersAsync(ctx context.Context, cid cid.Cid, _ int
}

func TestRoutingDiscovery(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

h1 := bhost.NewBlankHost(swarmt.GenSwarm(t))
h2 := bhost.NewBlankHost(swarmt.GenSwarm(t))
Expand Down Expand Up @@ -110,8 +109,7 @@ func TestRoutingDiscovery(t *testing.T) {
}

func TestDiscoveryRouting(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

h1 := bhost.NewBlankHost(swarmt.GenSwarm(t))
h2 := bhost.NewBlankHost(swarmt.GenSwarm(t))
Expand Down
12 changes: 4 additions & 8 deletions p2p/host/autonat/svc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ func makeAutoNATClient(t *testing.T) (host.Host, Client) {

// Note: these tests assume that the host has only private network addresses!
func TestAutoNATServiceDialRefused(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

c := makeAutoNATConfig(t)
defer c.host.Close()
Expand All @@ -68,8 +67,7 @@ func TestAutoNATServiceDialRefused(t *testing.T) {
}

func TestAutoNATServiceDialSuccess(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

c := makeAutoNATConfig(t)
defer c.host.Close()
Expand All @@ -88,8 +86,7 @@ func TestAutoNATServiceDialSuccess(t *testing.T) {
}

func TestAutoNATServiceDialRateLimiter(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

c := makeAutoNATConfig(t)
defer c.host.Close()
Expand Down Expand Up @@ -128,8 +125,7 @@ func TestAutoNATServiceDialRateLimiter(t *testing.T) {
}

func TestAutoNATServiceGlobalLimiter(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

c := makeAutoNATConfig(t)
defer c.host.Close()
Expand Down
12 changes: 4 additions & 8 deletions p2p/host/basic/basic_host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,7 @@ func TestHostProtoPreference(t *testing.T) {
}

func TestHostProtoMismatch(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

h1, h2 := getHostPair(t)
defer h1.Close()
Expand Down Expand Up @@ -469,8 +468,7 @@ func TestHostProtoPreknowledge(t *testing.T) {
}

func TestNewDialOld(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

h1, h2 := getHostPair(t)
defer h1.Close()
Expand Down Expand Up @@ -541,8 +539,7 @@ func TestNewStreamResolve(t *testing.T) {
}

func TestProtoDowngrade(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

h1, h2 := getHostPair(t)
defer h1.Close()
Expand Down Expand Up @@ -756,8 +753,7 @@ func TestHostAddrChangeDetection(t *testing.T) {
}

func TestNegotiationCancel(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

h1, h2 := getHostPair(t)
defer h1.Close()
Expand Down
4 changes: 1 addition & 3 deletions p2p/net/gostream/gostream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package gostream

import (
"bufio"
"context"
"io"
"testing"
"time"
Expand Down Expand Up @@ -38,8 +37,7 @@ func TestServerClient(t *testing.T) {
clientHost.Peerstore().AddAddrs(srvHost.ID(), srvHost.Addrs(), peerstore.PermanentAddrTTL)

var tag protocol.ID = "/testitytest"
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

done := make(chan struct{})
go func() {
Expand Down
6 changes: 2 additions & 4 deletions p2p/net/pnet/psk_conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ func setupPSKConns(_ context.Context, t *testing.T) (net.Conn, net.Conn) {
}

func TestPSKSimpelMessges(t *testing.T) {
ctx, cancel := context.WithCancel(context.TODO())
defer cancel()
ctx := t.Context()

psk1, psk2 := setupPSKConns(ctx, t)
msg1 := []byte("hello world")
Expand Down Expand Up @@ -56,8 +55,7 @@ func TestPSKSimpelMessges(t *testing.T) {
}

func TestPSKFragmentation(t *testing.T) {
ctx, cancel := context.WithCancel(context.TODO())
defer cancel()
ctx := t.Context()

psk1, psk2 := setupPSKConns(ctx, t)

Expand Down
3 changes: 1 addition & 2 deletions p2p/net/swarm/limiter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ func TestLimiterBasicDials(t *testing.T) {

resch := make(chan transport.DialUpdate)
pid := peer.ID("testpeer")
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

tryDialAddrs(ctx, l, pid, bads, resch)

Expand Down
3 changes: 1 addition & 2 deletions p2p/net/swarm/swarm_net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ func printConns(n network.Network) string {
}

func TestNetworkOpenStream(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

testString := "hello ipfs"

Expand Down
9 changes: 3 additions & 6 deletions p2p/protocol/circuitv2/relay/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ func addTransport(t *testing.T, h host.Host, upgrader transport.Upgrader) {
}

func TestBasicRelay(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

hosts, upgraders := getNetHosts(t, ctx, 3)
addTransport(t, hosts[0], upgraders[0])
Expand Down Expand Up @@ -205,8 +204,7 @@ func TestBasicRelay(t *testing.T) {
}

func TestRelayLimitTime(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

hosts, upgraders := getNetHosts(t, ctx, 3)
addTransport(t, hosts[0], upgraders[0])
Expand Down Expand Up @@ -279,8 +277,7 @@ func TestRelayLimitTime(t *testing.T) {
}

func TestRelayLimitData(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

hosts, upgraders := getNetHosts(t, ctx, 3)
addTransport(t, hosts[0], upgraders[0])
Expand Down
24 changes: 8 additions & 16 deletions p2p/protocol/identify/id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,7 @@ func TestLocalhostAddrFiltering(t *testing.T) {
// TestIdentifyPushWhileIdentifyingConn tests that the host waits to push updates if an identify is ongoing.
func TestIdentifyPushWhileIdentifyingConn(t *testing.T) {
t.Skip()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

h1 := blhost.NewBlankHost(swarmt.GenSwarm(t))
h2 := blhost.NewBlankHost(swarmt.GenSwarm(t))
Expand Down Expand Up @@ -436,8 +435,7 @@ func TestIdentifyPushWhileIdentifyingConn(t *testing.T) {
}

func TestIdentifyPushOnAddrChange(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

h1 := blhost.NewBlankHost(swarmt.GenSwarm(t))
h2 := blhost.NewBlankHost(swarmt.GenSwarm(t))
Expand Down Expand Up @@ -510,8 +508,7 @@ func TestIdentifyPushOnAddrChange(t *testing.T) {
}

func TestUserAgent(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

h1, err := libp2p.New(libp2p.UserAgent("foo"), libp2p.ListenAddrStrings("/ip4/127.0.0.1/tcp/0"))
if err != nil {
Expand Down Expand Up @@ -542,8 +539,7 @@ func TestNotListening(t *testing.T) {
// Make sure we don't panic if we're not listening on any addresses.
//
// https://github.com/libp2p/go-libp2p/issues/939
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

h1, err := libp2p.New(libp2p.NoListenAddrs)
if err != nil {
Expand All @@ -564,8 +560,7 @@ func TestNotListening(t *testing.T) {
}

func TestSendPush(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

h1 := blhost.NewBlankHost(swarmt.GenSwarm(t))
h2 := blhost.NewBlankHost(swarmt.GenSwarm(t))
Expand Down Expand Up @@ -729,8 +724,7 @@ func randString(n int) string {
}

func TestLargePushMessage(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

h1 := blhost.NewBlankHost(swarmt.GenSwarm(t))
h2 := blhost.NewBlankHost(swarmt.GenSwarm(t))
Expand Down Expand Up @@ -805,8 +799,7 @@ func TestLargePushMessage(t *testing.T) {
}

func TestIdentifyResponseReadTimeout(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

h1 := blhost.NewBlankHost(swarmt.GenSwarm(t))
h2 := blhost.NewBlankHost(swarmt.GenSwarm(t))
Expand Down Expand Up @@ -845,8 +838,7 @@ func TestIdentifyResponseReadTimeout(t *testing.T) {
}

func TestIncomingIDStreamsTimeout(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

protocols := []protocol.ID{identify.IDPush}

Expand Down
3 changes: 1 addition & 2 deletions p2p/protocol/ping/ping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import (
)

func TestPing(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()
h1, err := bhost.NewHost(swarmt.GenSwarm(t), nil)
require.NoError(t, err)
defer h1.Close()
Expand Down
4 changes: 1 addition & 3 deletions p2p/test/backpressure/backpressure_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package backpressure_tests

import (
"context"
"os"
"testing"
"time"
Expand All @@ -20,8 +19,7 @@ var log = logging.Logger("backpressure")
// TestStBackpressureStreamWrite tests whether streams see proper
// backpressure when writing data over the network streams.
func TestStBackpressureStreamWrite(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

h1, err := bhost.NewHost(swarmt.GenSwarm(t), nil)
require.NoError(t, err)
Expand Down
3 changes: 1 addition & 2 deletions p2p/test/transport/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -860,8 +860,7 @@ func TestDiscoverPeerIDFromSecurityNegotiation(t *testing.T) {

// runs a test to verify we can extract the peer ID from a target with just its address
t.Helper()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

// Use a bogus peer ID so that when we connect to the target we get an error telling
// us the targets real peer ID
Expand Down
Loading