mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
swarm/network: fix data races in TestInitialPeersMsg test
This commit is contained in:
parent
74acde4b08
commit
517476cbeb
2 changed files with 8 additions and 1 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue