Skip to content

Commit

Permalink
improve test name
Browse files Browse the repository at this point in the history
  • Loading branch information
sukunrt committed Dec 5, 2024
1 parent faeda47 commit e675e4b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
4 changes: 4 additions & 0 deletions p2p/net/swarm/dial_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package swarm

import (
"context"
"fmt"
"math"
"sync"
"time"
Expand Down Expand Up @@ -295,6 +296,9 @@ loop:
}
ad.dialed = true
ad.dialRankingDelay = now.Sub(ad.createdAt)
if _, err := ad.addr.ValueForProtocol(ma.P_WEBRTC_DIRECT); err == nil {
fmt.Println("dial ranking delay", ad.addr, ad.dialRankingDelay)
}
err := w.s.dialNextAddr(ad.ctx, w.peer, ad.addr, w.resch)
if err != nil {
// Errored without attempting a dial. This happens in case of
Expand Down
32 changes: 14 additions & 18 deletions p2p/test/basichost/basic_host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"strings"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -204,7 +203,7 @@ func TestAddrFactorCertHashAppend(t *testing.T) {
}, 5*time.Second, 100*time.Millisecond)
}

func TestWebRTCDirectDialDelay(t *testing.T) {
func TestOnlyWebRTCDirectDialNoDelay(t *testing.T) {
// This tests that only webrtc-direct dials are dialled immediately
// and not delayed by dial ranker.
h1, err := libp2p.New(
Expand All @@ -229,46 +228,43 @@ func TestWebRTCDirectDialDelay(t *testing.T) {
func TestWebRTCWithQUICManyConnections(t *testing.T) {
// Correctly fixes: https://github.com/libp2p/js-libp2p/issues/2805

// The server has both /quic-v1 and /webrtc-direct listen addresses
h, err := libp2p.New(
libp2p.Transport(libp2pquic.NewTransport),
libp2p.Transport(libp2pwebrtc.New),
libp2p.ListenAddrStrings("/ip4/0.0.0.0/udp/0/quic-v1"),
libp2p.ListenAddrStrings("/ip4/0.0.0.0/udp/0/webrtc-direct"),
libp2p.ResourceManager(&network.NullResourceManager{}),
)
require.NoError(t, err)
defer h.Close()

const N = 50
const N = 200
// These N dialers have both /quic-v1 and /webrtc-direct transports
var dialers [N]host.Host
for i := 0; i < N; i++ {
dialers[i], err = libp2p.New(libp2p.NoListenAddrs)
require.NoError(t, err)
defer dialers[i].Close()
}
// only webrtc dialer for dialing the peer later
// This dialer has only /webrtc-direct transport
d, err := libp2p.New(libp2p.Transport(libp2pwebrtc.New), libp2p.NoListenAddrs)
require.NoError(t, err)
defer d.Close()

startDial := make(chan struct{})
var wg sync.WaitGroup
wg.Add(N)
for i := 0; i < N; i++ {
go func() {
defer wg.Done()
<-startDial
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
// it is fine if the dial fails, we just want to take up all the webrtc
// listen queue
_ = dialers[i].Connect(ctx, peer.AddrInfo{ID: h.ID(), Addrs: h.Addrs()})
}()
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
// With happy eyeballs these dialers will connect over only /quic-v1
// and not stall the /webrtc-direct handshake goroutines.
// it is fine if the dial fails, we just want to ensure that there's space
// in the /webrtc-direct listen queue
_ = dialers[i].Connect(ctx, peer.AddrInfo{ID: h.ID(), Addrs: h.Addrs()})
}
close(startDial)
wg.Wait()

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
// The webrtc only dialer should be able to connect to the peer
err = d.Connect(ctx, peer.AddrInfo{ID: h.ID(), Addrs: h.Addrs()})
require.NoError(t, err)
}

0 comments on commit e675e4b

Please sign in to comment.