github.com/turingchain2020/turingchain@v1.1.21/system/p2p/dht/extension/mdns_test.go (about)

     1  package extension
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func Test_mdns(t *testing.T) {
    12  	ctx, cancel := context.WithCancel(context.Background())
    13  	defer cancel()
    14  
    15  	hosts := getNetHosts(ctx, 3, t)
    16  	connect(t, hosts[0], hosts[1])
    17  	_, err := NewMDNS(ctx, hosts[0], "33test123")
    18  	require.Nil(t, err)
    19  	_, err = NewMDNS(ctx, hosts[1], "33test123")
    20  	require.Nil(t, err)
    21  	tmdns, err := NewMDNS(ctx, hosts[2], "33test123")
    22  	require.Nil(t, err)
    23  
    24  	select {
    25  	case peerinfo := <-tmdns.PeerChan():
    26  		t.Log("findMdns", peerinfo.ID)
    27  	case <-time.After(time.Second * 10):
    28  		return
    29  	}
    30  
    31  }