fix(tests): flaky testdaemon (#1123)
This commit is contained in:
parent
3bf8a2907f
commit
4618f4c68f
|
@ -28,29 +28,3 @@ template asyncTest*(name: string, body: untyped): untyped =
|
|||
body
|
||||
)()
|
||||
)
|
||||
|
||||
template flakyAsyncTest*(name: string, attempts: int, body: untyped): untyped =
|
||||
test name:
|
||||
var attemptNumber = 0
|
||||
while attemptNumber < attempts:
|
||||
let isLastAttempt = attemptNumber == attempts - 1
|
||||
inc attemptNumber
|
||||
try:
|
||||
waitFor(
|
||||
(
|
||||
proc() {.async.} =
|
||||
body
|
||||
)()
|
||||
)
|
||||
except Exception as e:
|
||||
if isLastAttempt:
|
||||
raise e
|
||||
else:
|
||||
testStatusIMPL = TestStatus.FAILED
|
||||
finally:
|
||||
if not isLastAttempt:
|
||||
if testStatusIMPL == TestStatus.FAILED:
|
||||
# Retry
|
||||
testStatusIMPL = TestStatus.OK
|
||||
else:
|
||||
break
|
||||
|
|
|
@ -162,7 +162,7 @@ macro checkUntilCustomTimeout*(timeout: Duration, code: untyped): untyped =
|
|||
if `combinedBoolExpr`:
|
||||
return
|
||||
else:
|
||||
await sleepAsync(1.millis)
|
||||
await sleepAsync(100.millis)
|
||||
|
||||
await checkExpiringInternal()
|
||||
|
||||
|
|
|
@ -38,41 +38,12 @@ proc connectStreamTest(): Future[bool] {.async.} =
|
|||
var stream = await api1.openStream(id2.peer, protos)
|
||||
let sent = await stream.transp.write(test & "\r\n")
|
||||
doAssert(sent == len(test) + 2)
|
||||
var check = await wait(testFuture, 10.seconds)
|
||||
doAssert(check == test)
|
||||
doAssert((await wait(testFuture, 10.seconds)) == test)
|
||||
await stream.close()
|
||||
await api1.close()
|
||||
await api2.close()
|
||||
result = true
|
||||
|
||||
# proc provideCidTest(): Future[bool] {.async.} =
|
||||
# var api1 = await newDaemonApi({DHTFull})
|
||||
# var api2 = await newDaemonApi({DHTFull})
|
||||
# var msg = "ethereum2-beacon-chain"
|
||||
# var bmsg = cast[seq[byte]](msg)
|
||||
# var mh = MultiHash.digest("sha2-256", bmsg)
|
||||
# var cid = Cid.init(CIDv1, multiCodec("dag-pb"), mh)
|
||||
|
||||
# var id1 = await api1.identity()
|
||||
# var id2 = await api2.identity()
|
||||
|
||||
# await api1.connect(id2.peer, id2.addresses)
|
||||
|
||||
# while true:
|
||||
# var peers = await api1.listPeers()
|
||||
# if len(peers) > 0:
|
||||
# break
|
||||
|
||||
# await api1.dhtProvide(cid)
|
||||
# var peers = await api2.dhtFindProviders(cid, 10)
|
||||
|
||||
# if len(peers) == 1:
|
||||
# if peers[0].peer == id1.peer:
|
||||
# result = true
|
||||
|
||||
# await api1.close()
|
||||
# await api2.close()
|
||||
|
||||
proc pubsubTest(f: set[P2PDaemonFlags]): Future[bool] {.async.} =
|
||||
var pubsubData = "TEST MESSAGE"
|
||||
var msgData = cast[seq[byte]](pubsubData)
|
||||
|
@ -143,10 +114,9 @@ when isMainModule:
|
|||
test "Connect/Accept peer/stream test":
|
||||
check:
|
||||
waitFor(connectStreamTest()) == true
|
||||
# test "Provide CID test":
|
||||
# check:
|
||||
# waitFor(provideCidTest()) == true
|
||||
flakyAsyncTest "GossipSub test", attempts = 4:
|
||||
check (await pubsubTest({PSGossipSub})) == true
|
||||
flakyAsyncTest "FloodSub test", attempts = 4:
|
||||
check (await pubsubTest({PSFloodSub})) == true
|
||||
asyncTest "GossipSub test":
|
||||
checkUntilTimeout:
|
||||
(await pubsubTest({PSGossipSub}))
|
||||
asyncTest "FloodSub test":
|
||||
checkUntilTimeout:
|
||||
(await pubsubTest({PSFloodSub}))
|
||||
|
|
Loading…
Reference in New Issue