github.com/qri-io/qri@v0.10.1-0.20220104210721-c771715036cb/p2p/test/p2ptest_test.go (about)

     1  package p2ptest
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  )
     7  
     8  // Ensure that when we use ConnectNodes, we are creating a basic connection
     9  // between two nodes
    10  // - we have connections to each peer
    11  // - we have the addrs of each peer
    12  // - we have a tag on each peer
    13  // - we have the protocols each peer supports
    14  func TestConnectNodes(t *testing.T) {
    15  	t.Skip("ramfox: this test is flakey & ConnectNodes is due for a refactoring, skipping for now")
    16  	ctx := context.Background()
    17  	f := NewTestNodeFactory(NewTestableNode)
    18  	testNodes, err := NewTestDirNetwork(ctx, f)
    19  	if err != nil {
    20  		t.Error(err)
    21  		return
    22  	}
    23  
    24  	if err := ConnectNodes(ctx, testNodes); err != nil {
    25  		t.Error(err)
    26  	}
    27  
    28  	for _, node := range testNodes {
    29  		// test that each conn has a connection to at least one peer id
    30  		pid := node.SimpleAddrInfo().ID
    31  		for _, rnode := range testNodes {
    32  			rpid := rnode.SimpleAddrInfo().ID
    33  			// dont need to check for connections to self
    34  			if pid == rpid {
    35  				continue
    36  			}
    37  			protos, err := node.Host().Peerstore().SupportsProtocols(rpid, string(TestQriProtocolID))
    38  			if err != nil {
    39  				t.Errorf("node %s, error getting %s's protocols", pid, rpid)
    40  			}
    41  			if len(protos) == 0 {
    42  				t.Errorf("node %s does not have a record that node %s aka can communicate over the testQri protocol", pid, rpid)
    43  			}
    44  			conns := node.Host().Network().ConnsToPeer(rpid)
    45  			if len(conns) == 0 {
    46  				t.Errorf("node %s has no connections to node %s", pid, rpid)
    47  			}
    48  			addrs := node.Host().Peerstore().Addrs(rpid)
    49  			if len(addrs) == 0 {
    50  				t.Errorf("node %s has no addrs for node %s", pid, rpid)
    51  			}
    52  			tag := node.Host().ConnManager().GetTagInfo(rpid)
    53  			if tag == nil {
    54  				t.Errorf("node %s has not tag info on node %s", pid, rpid)
    55  			}
    56  		}
    57  	}
    58  }