You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.1 KiB

package discovery
import (
"context"
"testing"
"time"
"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/peer"
swarmt "github.com/libp2p/go-libp2p-swarm/testing"
bhost "github.com/libp2p/go-libp2p/p2p/host/basic"
)
type DiscoveryNotifee struct {
h host.Host
}
func (n *DiscoveryNotifee) HandlePeerFound(pi peer.AddrInfo) {
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(swarmt.GenSwarm(t, ctx))
b := bhost.New(swarmt.GenSwarm(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, peer.AddrInfo{ID: b.ID()})
if err != nil {
t.Fatal(err)
}
}