Add a template to stop the test when a storage request fails

This commit is contained in:
Arnaud 2025-07-02 16:43:08 +02:00
parent f3311cca30
commit 69b0bf3b8a
No known key found for this signature in database
GPG Key ID: B8FBC178F10CA7AE
2 changed files with 50 additions and 19 deletions

View File

@ -447,23 +447,24 @@ marketplacesuite(name = "Marketplace payouts"):
discard await waitForRequestToStart()
# Here we will check that for each provider, the total remaining collateral
# will match the available slots.
# So if a SP hosts 1 slot, it should have enough total remaining collateral
# to host 2 more slots.
for provider in providers():
let client = provider.client
check eventually(
block:
try:
let availabilities = (await client.getAvailabilities()).get
let availability = availabilities[0]
let slots = (await client.getSlots()).get
let availableSlots = (3 - slots.len).u256
stopOnRequestFailed:
# Here we will check that for each provider, the total remaining collateral
# will match the available slots.
# So if a SP hosts 1 slot, it should have enough total remaining collateral
# to host 2 more slots.
for provider in providers():
let client = provider.client
check eventually(
block:
try:
let availabilities = (await client.getAvailabilities()).get
let availability = availabilities[0]
let slots = (await client.getSlots()).get
let availableSlots = (3 - slots.len).u256
availability.totalRemainingCollateral ==
availableSlots * slotSize * minPricePerBytePerSecond
except HttpConnectionError:
return false,
timeout = 30 * 1000,
)
availability.totalRemainingCollateral ==
availableSlots * slotSize * minPricePerBytePerSecond
except HttpConnectionError:
return false,
timeout = 30 * 1000,
)

View File

@ -34,6 +34,36 @@ template marketplacesuite*(name: string, body: untyped) =
if not cond:
fail(reason)
template stopOnRequestFailed(tbody: untyped) =
let completed = newAsyncEvent()
let mainFut = (
proc(): Future[void] {.async.} =
tbody
completed.fire()
)()
let fastFailFut = (
proc(): Future[void] {.async.} =
try:
await requestFailedEvent.wait().wait(timeout = chronos.seconds(60))
completed.fire()
raise newException(TestFailedError, "storage request has failed")
except AsyncTimeoutError:
discard
)()
await completed.wait().wait(timeout = chronos.seconds(60 * 30))
if not fastFailFut.completed:
await fastFailFut.cancelAndWait()
if mainFut.failed:
raise mainFut.error
if fastFailFut.failed:
raise fastFailFut.error
proc onRequestStarted(eventResult: ?!RequestFulfilled) {.raises: [].} =
requestStartedEvent.fire()