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:
parent
6df0c9ab40
commit
13bbf2b052
|
@ -120,9 +120,8 @@ suite "NetworkStore engine - 2 nodes":
|
||||||
.engine
|
.engine
|
||||||
.taskQueue
|
.taskQueue
|
||||||
.pushOrUpdateNoWait(peerCtx1).isOk
|
.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":
|
test "Should get blocks from remote":
|
||||||
let blocks = await allFinished(
|
let blocks = await allFinished(
|
||||||
|
@ -148,11 +147,10 @@ suite "NetworkStore engine - 2 nodes":
|
||||||
let blocks = await allFinished(
|
let blocks = await allFinished(
|
||||||
blocks2.mapIt( nodeCmps1.networkStore.getBlock(it.cid) ))
|
blocks2.mapIt( nodeCmps1.networkStore.getBlock(it.cid) ))
|
||||||
|
|
||||||
await sleepAsync(100.millis)
|
let channel = !peerCtx1.paymentChannel
|
||||||
|
let wallet = nodeCmps2.wallet
|
||||||
|
|
||||||
let
|
check eventually wallet.balance(channel, Asset) > 0
|
||||||
channel = !peerCtx1.paymentChannel
|
|
||||||
check nodeCmps2.wallet.balance(channel, Asset) > 0
|
|
||||||
|
|
||||||
suite "NetworkStore - multiple nodes":
|
suite "NetworkStore - multiple nodes":
|
||||||
let
|
let
|
||||||
|
|
|
@ -9,8 +9,9 @@ import pkg/codex/rng
|
||||||
import ./helpers/nodeutils
|
import ./helpers/nodeutils
|
||||||
import ./helpers/randomchunker
|
import ./helpers/randomchunker
|
||||||
import ./helpers/mockdiscovery
|
import ./helpers/mockdiscovery
|
||||||
|
import ./helpers/eventually
|
||||||
|
|
||||||
export randomchunker, nodeutils, mockdiscovery
|
export randomchunker, nodeutils, mockdiscovery, eventually
|
||||||
|
|
||||||
# NOTE: The meaning of equality for blocks
|
# NOTE: The meaning of equality for blocks
|
||||||
# is changed here, because blocks are now `ref`
|
# is changed here, because blocks are now `ref`
|
||||||
|
|
|
@ -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()
|
Loading…
Reference in New Issue