Fix test that was failing intermittently

Give test more time to complete but do not increase
sleep time more than necessary, by introducing
waiting loop for test purposes.
This commit is contained in:
Mark Spanbroek 2022-07-18 10:46:24 +02:00 committed by markspanbroek
parent 6df0c9ab40
commit 13bbf2b052
3 changed files with 19 additions and 7 deletions

View File

@ -120,9 +120,8 @@ suite "NetworkStore engine - 2 nodes":
.engine
.taskQueue
.pushOrUpdateNoWait(peerCtx1).isOk
await sleepAsync(100.millis)
check nodeCmps1.localStore.hasBlock(blk.cid)
check eventually nodeCmps1.localStore.hasBlock(blk.cid)
test "Should get blocks from remote":
let blocks = await allFinished(
@ -148,11 +147,10 @@ suite "NetworkStore engine - 2 nodes":
let blocks = await allFinished(
blocks2.mapIt( nodeCmps1.networkStore.getBlock(it.cid) ))
await sleepAsync(100.millis)
let channel = !peerCtx1.paymentChannel
let wallet = nodeCmps2.wallet
let
channel = !peerCtx1.paymentChannel
check nodeCmps2.wallet.balance(channel, Asset) > 0
check eventually wallet.balance(channel, Asset) > 0
suite "NetworkStore - multiple nodes":
let

View File

@ -9,8 +9,9 @@ import pkg/codex/rng
import ./helpers/nodeutils
import ./helpers/randomchunker
import ./helpers/mockdiscovery
import ./helpers/eventually
export randomchunker, nodeutils, mockdiscovery
export randomchunker, nodeutils, mockdiscovery, eventually
# NOTE: The meaning of equality for blocks
# is changed here, because blocks are now `ref`

View File

@ -0,0 +1,13 @@
import pkg/chronos
template eventually*(condition: untyped, timeout = 5.seconds): bool =
proc loop: Future[bool] {.async.} =
let start = Moment.now()
while true:
if condition:
return true
if Moment.now() > (start + timeout):
return false
else:
await sleepAsync(1.millis)
await loop()