nwaku/tests/testlib/futures.nim
Álex Cabeza Romero 817b2e067a
test(lightpush): Lightpush functional tests (#2269)
* Add ligthpush payload tests.
* Add end to end lightpush tests.
* updating vendor/nim-unittest2 to protect against core dump issue
* Enable "Valid Payload Sizes" test again
---------
Co-authored-by: Ivan FB <128452529+Ivansete-status@users.noreply.github.com>
2024-02-06 17:37:42 +01:00

37 lines
1.1 KiB
Nim

import chronos
import ../../../waku/[waku_core/message, waku_store]
const
FUTURE_TIMEOUT* = 1.seconds
FUTURE_TIMEOUT_LONG* = 10.seconds
proc newPushHandlerFuture*(): Future[(string, WakuMessage)] =
newFuture[(string, WakuMessage)]()
proc newBoolFuture*(): Future[bool] =
newFuture[bool]()
proc newHistoryFuture*(): Future[HistoryQuery] =
newFuture[HistoryQuery]()
proc toResult*[T](future: Future[T]): Result[T, string] =
if future.cancelled():
return chronos.err("Future timeouted before completing.")
elif future.finished() and not future.failed():
return chronos.ok(future.read())
else:
return chronos.err("Future finished but failed.")
proc toResult*(future: Future[void]): Result[void, string] =
if future.cancelled():
return chronos.err("Future timeouted before completing.")
elif future.finished() and not future.failed():
return chronos.ok()
else:
return chronos.err("Future finished but failed.")
proc waitForResult*[T](future: Future[T], timeout = FUTURE_TIMEOUT): Future[Result[T, string]] {.async.} =
discard await future.withTimeout(timeout)
return future.toResult()