package discovery import ( "context" "testing" "time" bhost "github.com/libp2p/go-libp2p/p2p/host/basic" host "github.com/libp2p/go-libp2p-host" swarmt "github.com/libp2p/go-libp2p-swarm/testing" 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(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, pstore.PeerInfo{ID: b.ID()}) if err != nil { t.Fatal(err) } }