From ad17048bd49110f03797b36df6e6bf3675e777d1 Mon Sep 17 00:00:00 2001 From: Fabio Barone Date: Fri, 22 Mar 2019 18:13:23 -0500 Subject: [PATCH] swarm/network: use hive.depth and fix race condition --- swarm/network/discovery_test.go | 7 +++---- swarm/network/protocol_test.go | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/swarm/network/discovery_test.go b/swarm/network/discovery_test.go index dcec509f7a..272c1ec3e5 100644 --- a/swarm/network/discovery_test.go +++ b/swarm/network/discovery_test.go @@ -130,7 +130,9 @@ func testSubpeersMsg(t *testing.T) { control := s.Nodes[0] // get BzzAddr of the control + hive.lock.Lock() controlBzz := hive.peers[control.ID()].Over() + hive.lock.Unlock() // build a control kademlia for the control node from the address pool // we use this so we can identify the actual `controlDepth` of the control node controlKad := NewKademlia(controlBzz, NewKadParams()) @@ -155,9 +157,6 @@ func testSubpeersMsg(t *testing.T) { return true }) - // this is the hive's depth, which will be sent first to the control node initiating the test exchanges - hiveDepth := hive.NeighbourhoodDepth() - // if the controlDepth is 0, nothing will happen, so in this case artificially set it to 2 if controlDepth == 0 { controlDepth = 2 @@ -172,7 +171,7 @@ func testSubpeersMsg(t *testing.T) { Expects: []p2ptest.Expect{ { Code: 1, - Msg: &subPeersMsg{Depth: uint8(hiveDepth)}, + Msg: &subPeersMsg{Depth: uint8(hive.depth)}, Peer: control.ID(), }, }, diff --git a/swarm/network/protocol_test.go b/swarm/network/protocol_test.go index 1ab47eafe7..f5f9e9692b 100644 --- a/swarm/network/protocol_test.go +++ b/swarm/network/protocol_test.go @@ -132,7 +132,7 @@ func newPreconnectedBzzBaseTester(t *testing.T, waitC chan struct{}, preConns [] s := p2ptest.NewProtocolTester(prvkey, n, protocol) for _, node := range s.Nodes { - log.Warn("node", "node", node) + log.Debug("node", "node", node) cs[node.ID().String()] = make(chan bool) }