fix(tests): flaky testdaemon (#1123)

This commit is contained in:
diegomrsantos 2024-06-13 11:07:36 +02:00 committed by GitHub
parent 3bf8a2907f
commit 4618f4c68f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 64 deletions

View File

@ -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

View File

@ -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()

View File

@ -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}))