fix flaky ping test

This commit is contained in:
Ivan Folgueira Bande 2026-01-30 10:42:16 +01:00
parent beb1dde1b5
commit cc00ceffe0
No known key found for this signature in database
GPG Key ID: 3C117481F89E24A7
2 changed files with 12 additions and 5 deletions

View File

@ -23,11 +23,8 @@ suite "Waku Keepalive":
proc pingHandler(peerId: PeerID) {.async, gcsafe.} =
info "Ping received"
check:
peerId == node1.switch.peerInfo.peerId
completionFut.complete(true)
let checkPeerIdMatch = peerId == node1.switch.peerInfo.peerId
completionFut.complete(checkPeerIdMatch)
await node1.start()
(await node1.mountRelay()).isOkOr:
@ -44,6 +41,12 @@ suite "Waku Keepalive":
await node1.connectToNodes(@[node2.switch.peerInfo.toRemotePeerInfo()])
## Wait a while till the connection is established
for _ in 0 ..< 20:
if node1.peerManager.isPeerConnected(node2.switch.peerInfo.peerId):
break
await sleepAsync(100.millis)
let healthMonitor = NodeHealthMonitor()
healthMonitor.setNodeToHealthMonitor(node1)
healthMonitor.startKeepalive(2.seconds).isOkOr:

View File

@ -500,6 +500,10 @@ proc connectedPeers*(
return (inPeers, outPeers)
proc isPeerConnected*(pm: PeerManager, peerId: PeerId): bool
let (inPeers, outPeers) = pm.connectedPeers()
return inPeers.contains(peerId) or outPeers.contains(peerId)
proc disconnectAllPeers*(pm: PeerManager) {.async.} =
let (inPeerIds, outPeerIds) = pm.connectedPeers()
let connectedPeers = concat(inPeerIds, outPeerIds)