github.com/metacurrency/holochain@v0.1.0-alpha-26.0.20200915073418-5c83169c9b5b/notifi_test.go (about) 1 package holochain 2 3 import ( 4 "testing" 5 ) 6 7 func TestNotifieeMultipleConn(t *testing.T) { 8 nodesCount := 2 9 mt := setupMultiNodeTesting(nodesCount) 10 defer mt.cleanupMultiNodeTesting() 11 nodes := mt.nodes 12 13 n1 := nodes[0].node 14 n2 := nodes[1].node 15 16 nn1 := (*netNotifiee)(n1) 17 nn2 := (*netNotifiee)(n2) 18 19 connect(t, mt.ctx, nodes[0], nodes[1]) 20 c12 := n1.host.Network().ConnsToPeer(n2.HashAddr)[0] 21 c21 := n2.host.Network().ConnsToPeer(n1.HashAddr)[0] 22 23 // Pretend to reestablish/re-kill connection 24 nn1.Connected(n1.host.Network(), c12) 25 nn2.Connected(n2.host.Network(), c21) 26 27 if !checkRoutingTable(n1, n2) { 28 t.Fatal("no routes") 29 } 30 nn1.Disconnected(n1.host.Network(), c12) 31 nn2.Disconnected(n2.host.Network(), c21) 32 33 if !checkRoutingTable(n1, n2) { 34 t.Fatal("no routes") 35 } 36 37 for _, conn := range n1.host.Network().ConnsToPeer(n2.HashAddr) { 38 conn.Close() 39 } 40 for _, conn := range n2.host.Network().ConnsToPeer(n1.HashAddr) { 41 conn.Close() 42 } 43 44 if checkRoutingTable(n1, n2) { 45 t.Fatal("routes") 46 } 47 } 48 49 func TestNotifieeFuzz(t *testing.T) { 50 nodesCount := 2 51 mt := setupMultiNodeTesting(nodesCount) 52 defer mt.cleanupMultiNodeTesting() 53 nodes := mt.nodes 54 55 n1 := nodes[0].node 56 n2 := nodes[1].node 57 58 for i := 0; i < 100; i++ { 59 connectNoSync(t, mt.ctx, nodes[0], nodes[1]) 60 for _, conn := range n1.host.Network().ConnsToPeer(n2.HashAddr) { 61 conn.Close() 62 } 63 } 64 if checkRoutingTable(n1, n2) { 65 t.Fatal("should not have routes") 66 } 67 connect(t, mt.ctx, nodes[0], nodes[1]) 68 } 69 70 func checkRoutingTable(a, b *Node) bool { 71 // loop until connection notification has been received. 72 // under high load, this may not happen as immediately as we would like. 73 return a.routingTable.Find(b.HashAddr) != "" && b.routingTable.Find(a.HashAddr) != "" 74 }