diff --git a/swarm/network/discovery_test.go b/swarm/network/discovery_test.go index 04e1b36fed..137205ca60 100644 --- a/swarm/network/discovery_test.go +++ b/swarm/network/discovery_test.go @@ -160,7 +160,10 @@ func testInitialPeersMsg(t *testing.T, peerPO, peerDepth int) { // block until control peer is found among hive peers found := false for attempts := 0; attempts < 20; attempts++ { - if _, found = hive.peers[peerID]; found { + hive.lock.Lock() + _, found = hive.peers[peerID] + hive.lock.Unlock() + if found { break } time.Sleep(1 * time.Millisecond) @@ -171,7 +174,9 @@ func testInitialPeersMsg(t *testing.T, peerPO, peerDepth int) { } // pivotDepth is the advertised depth of the pivot node we expect in the outgoing subPeersMsg + hive.Kademlia.lock.RLock() // protect Kademlia.conns that are read in Kademlia.saturation() pivotDepth := hive.saturation() + hive.Kademlia.lock.RUnlock() // the test exchange is as follows: // 1. pivot sends to the control peer a `subPeersMsg` advertising its depth (ignored) // 2. peer sends to pivot a `subPeersMsg` advertising its own depth (arbitrarily chosen) diff --git a/swarm/network/protocol_test.go b/swarm/network/protocol_test.go index b562a42534..c65844b97d 100644 --- a/swarm/network/protocol_test.go +++ b/swarm/network/protocol_test.go @@ -131,9 +131,11 @@ func newBzzBaseTesterWithAddrs(prvkey *ecdsa.PrivateKey, addrs [][]byte, spec *p ProtocolTester: s, cs: cs, } + mu.Lock() for _, n := range pt.Nodes { nodeAddrs = append(nodeAddrs, nodeToAddr[n.ID()]) } + mu.Unlock() return pt, nodeAddrs, nil }