fix(networking): fix flaky peerstore test (#1554)

This commit is contained in:
Alvaro Revuelta 2023-02-13 18:10:20 +01:00 committed by GitHub
parent 2f4415de02
commit 2ca2b3fc8a
2 changed files with 4 additions and 2 deletions

View File

@ -529,7 +529,7 @@ procSuite "Peer Manager":
pm.peerStore[ConnectionBook][peers[10].peerId] = Connected
pm.peerStore[ConnectionBook][peers[12].peerId] = Connected
# Prune the peerstore
# Prune the peerstore (current=15, target=5)
pm.prunePeerStore()
check:

View File

@ -405,7 +405,9 @@ proc prunePeerStore*(pm: PeerManager) =
# prune peers with too many failed attempts
var pruned = 0
for peerId in pm.peerStore[NumberFailedConnBook].book.keys:
# copy to avoid modifying the book while iterating
let peerKeys = toSeq(pm.peerStore[NumberFailedConnBook].book.keys)
for peerId in peerKeys:
if peersToPrune - pruned == 0:
break
if pm.peerStore[NumberFailedConnBook][peerId] >= pm.maxFailedAttempts: