Browse Source

Merge pull request #995 from libp2p/fix/tests

fix tests
pull/972/head
Steven Allen 4 years ago
committed by GitHub
parent
commit
35c2dbd600
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      p2p/host/relay/autorelay_test.go
  2. 4
      p2p/protocol/identify/id_test.go

18
p2p/host/relay/autorelay_test.go

@ -3,6 +3,7 @@ package relay_test
import (
"context"
"net"
"strings"
"sync"
"testing"
"time"
@ -132,7 +133,22 @@ func TestAutoRelay(t *testing.T) {
if err != nil {
t.Fatal(err)
}
_, err = libp2p.New(ctx, libp2p.EnableRelay(circuit.OptHop), libp2p.EnableAutoRelay(), libp2p.Routing(makeRouting))
// announce dns addrs because filter out private addresses from relays,
// and we consider dns addresses "public".
_, err = libp2p.New(ctx,
libp2p.EnableRelay(circuit.OptHop),
libp2p.EnableAutoRelay(),
libp2p.Routing(makeRouting),
libp2p.AddrsFactory(func(addrs []ma.Multiaddr) []ma.Multiaddr {
for i, addr := range addrs {
saddr := addr.String()
if strings.HasPrefix(saddr, "/ip4/127.0.0.1/") {
addrNoIP := strings.TrimPrefix(saddr, "/ip4/127.0.0.1")
addrs[i] = ma.StringCast("/dns4/localhost" + addrNoIP)
}
}
return addrs
}))
if err != nil {
t.Fatal(err)
}

4
p2p/protocol/identify/id_test.go

@ -788,7 +788,7 @@ func TestLargeIdentifyMessage(t *testing.T) {
// add protocol strings to make the message larger
// about 2K of protocol strings
for i := 0; i < 500; i++ {
r := "rand" + string(i)
r := fmt.Sprintf("rand%d", i)
h1.SetStreamHandler(protocol.ID(r), func(network.Stream) {})
h2.SetStreamHandler(protocol.ID(r), func(network.Stream) {})
}
@ -898,7 +898,7 @@ func TestLargePushMessage(t *testing.T) {
// add protocol strings to make the message larger
// about 2K of protocol strings
for i := 0; i < 500; i++ {
r := "rand" + string(i)
r := fmt.Sprintf("rand%d", i)
h1.SetStreamHandler(protocol.ID(r), func(network.Stream) {})
h2.SetStreamHandler(protocol.ID(r), func(network.Stream) {})
}

Loading…
Cancel
Save