-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathmdns_test.go
56 lines (40 loc) · 1.08 KB
/
mdns_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package discovery
import (
"context"
"testing"
"time"
bhost "github.com/libp2p/go-libp2p/p2p/host/basic"
host "github.com/libp2p/go-libp2p-host"
netutil "github.com/libp2p/go-libp2p-netutil"
pstore "github.com/libp2p/go-libp2p-peerstore"
)
type DiscoveryNotifee struct {
h host.Host
}
func (n *DiscoveryNotifee) HandlePeerFound(pi pstore.PeerInfo) {
n.h.Connect(context.Background(), pi)
}
func TestMdnsDiscovery(t *testing.T) {
//TODO: re-enable when the new lib will get integrated
t.Skip("TestMdnsDiscovery fails randomly with current lib")
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
a := bhost.New(netutil.GenSwarmNetwork(t, ctx))
b := bhost.New(netutil.GenSwarmNetwork(t, ctx))
sa, err := NewMdnsService(ctx, a, time.Second, "someTag")
if err != nil {
t.Fatal(err)
}
sb, err := NewMdnsService(ctx, b, time.Second, "someTag")
if err != nil {
t.Fatal(err)
}
_ = sb
n := &DiscoveryNotifee{a}
sa.RegisterNotifee(n)
time.Sleep(time.Second * 2)
err = a.Connect(ctx, pstore.PeerInfo{ID: b.ID()})
if err != nil {
t.Fatal(err)
}
}