swarm/network: fix data races in TestInitialPeersMsg test (#19490)

* swarm/network: fix data races in TestInitialPeersMsg test

* swarm/network: add Kademlia.Saturation method with lock

* swarm/network: add Hive.Peer method to safely retrieve a bzz peer

* swarm/network: remove duplicate comment

* p2p/testing: prevent goroutine leak in ProtocolTester

* swarm/network: fix data race in newBzzBaseTesterWithAddrs

* swarm/network: fix goroutone leaks in testInitialPeersMsg

* swarm/network: raise number of peer check attempts in testInitialPeersMsg

* swarm/network: use Hive.Peer in Hive.PeerInfo function

* swarm/network: reduce the scope of mutex lock in newBzzBaseTesterWithAddrs

* swarm/storage: disable TestCleanIndex with race detector
This commit is contained in:
Janoš Guljaš
2019-04-25 21:33:18 +02:00
committed by Viktor Trón
parent 92a849a509
commit 3873a7314d
6 changed files with 37 additions and 10 deletions

View File

@@ -154,13 +154,15 @@ func testInitialPeersMsg(t *testing.T, peerPO, peerDepth int) {
if err != nil {
t.Fatal(err)
}
defer s.Stop()
// peerID to use in the protocol tester testExchange expect/trigger
peerID := s.Nodes[0].ID()
// block until control peer is found among hive peers
found := false
for attempts := 0; attempts < 20; attempts++ {
if _, found = hive.peers[peerID]; found {
for attempts := 0; attempts < 2000; attempts++ {
found = hive.Peer(peerID) != nil
if found {
break
}
time.Sleep(1 * time.Millisecond)
@@ -171,7 +173,7 @@ func testInitialPeersMsg(t *testing.T, peerPO, peerDepth int) {
}
// pivotDepth is the advertised depth of the pivot node we expect in the outgoing subPeersMsg
pivotDepth := hive.saturation()
pivotDepth := hive.Saturation()
// 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)