From 591895f2253c252a915cde01b87033012ee7f74e Mon Sep 17 00:00:00 2001 From: gmega Date: Wed, 10 Jan 2024 18:25:57 -0300 Subject: [PATCH] add minimal changes to get compilation of tests with Chronos V4 + latest asynctest --- codex/utils/asyncspawn.nim | 4 ++ tests/checktest.nim | 25 +++++----- .../blockexchange/discovery/testdiscovery.nim | 12 +++-- .../discovery/testdiscoveryengine.nim | 28 ++++++++--- .../blockexchange/engine/testblockexc.nim | 2 +- .../codex/blockexchange/engine/testengine.nim | 22 ++++----- .../blockexchange/protobuf/testpayments.nim | 2 +- .../blockexchange/protobuf/testpresence.nim | 4 +- tests/codex/blockexchange/testnetwork.nim | 49 ++++++++++++++----- .../codex/blockexchange/testpeerctxstore.nim | 2 +- .../codex/blockexchange/testpendingblocks.nim | 2 +- tests/codex/helpers/mockclock.nim | 2 +- tests/codex/helpers/mockdiscovery.nim | 10 ++-- tests/codex/sales/states/testfilled.nim | 2 +- .../codex/sales/states/testinitialproving.nim | 2 +- tests/codex/sales/states/testproving.nim | 2 +- .../sales/states/testsimulatedproving.nim | 2 +- tests/codex/sales/states/testunknown.nim | 2 +- tests/codex/sales/testreservations.nim | 2 +- tests/codex/sales/testsales.nim | 7 +-- tests/codex/sales/testsalesagent.nim | 2 +- tests/codex/sales/testslotqueue.nim | 3 +- tests/codex/stores/commonstoretests.nim | 2 +- tests/codex/stores/testcachestore.nim | 2 +- tests/codex/stores/testkeyutils.nim | 2 +- tests/codex/stores/testmaintenance.nim | 2 +- tests/codex/stores/testrepostore.nim | 2 +- tests/codex/testasyncheapqueue.nim | 2 +- tests/codex/testasyncstreamwrapper.nim | 2 +- tests/codex/testchunking.nim | 2 +- tests/codex/testerasure.nim | 6 ++- tests/codex/testmanifest.nim | 4 +- tests/codex/testpurchasing.nim | 2 +- tests/codex/teststorestream.nim | 2 +- tests/codex/testvalidation.nim | 2 +- tests/codex/utils/testasyncstatemachine.nim | 5 +- tests/codex/utils/testthen.nim | 2 +- tests/codex/utils/testtimer.nim | 2 +- tests/codex/utils/testtrackedfutures.nim | 2 +- tests/contracts/testDeployment.nim | 2 +- tests/ethertest.nim | 2 +- tests/helpers/multisetup.nim | 14 ++++-- tests/testTaiko.nim | 2 +- vendor/asynctest | 2 +- 44 files changed, 158 insertions(+), 95 deletions(-) diff --git a/codex/utils/asyncspawn.nim b/codex/utils/asyncspawn.nim index 6717e5e1..6835a4fa 100644 --- a/codex/utils/asyncspawn.nim +++ b/codex/utils/asyncspawn.nim @@ -8,3 +8,7 @@ proc asyncSpawn*(future: Future[void], ignore: type CatchableError) = discard asyncSpawn ignoringError() +proc asyncSpawn*[T](future: Future[T]): void = + proc task() {.async.} = discard await future + asyncSpawn task() + diff --git a/tests/checktest.nim b/tests/checktest.nim index 33848a78..383a664b 100644 --- a/tests/checktest.nim +++ b/tests/checktest.nim @@ -3,25 +3,28 @@ import ./helpers ## Unit testing suite that calls checkTrackers in teardown to check for memory leaks using chronos trackers. template checksuite*(name, body) = suite name: - multisetup() - teardown: - checkTrackers() + proc suiteProc = + multisetup() + + teardown: + checkTrackers() - # Avoids GcUnsafe2 warnings with chronos - # Copied from asynctest/templates.nim - let suiteproc = proc = body - suiteproc() + suiteProc() template asyncchecksuite*(name, body) = suite name: - asyncmultisetup() - teardown: - checkTrackers() + proc suiteProc = + asyncmultisetup() - body + teardown: + checkTrackers() + + body + + suiteProc() export helpers diff --git a/tests/codex/blockexchange/discovery/testdiscovery.nim b/tests/codex/blockexchange/discovery/testdiscovery.nim index ad02d6cb..8a263393 100644 --- a/tests/codex/blockexchange/discovery/testdiscovery.nim +++ b/tests/codex/blockexchange/discovery/testdiscovery.nim @@ -2,7 +2,7 @@ import std/sequtils import std/sugar import std/tables -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/chronos import pkg/libp2p/errors @@ -120,7 +120,10 @@ asyncchecksuite "Block Advertising and Discovery": advertised = newFuture[Cid]() blockDiscovery - .publishBlockProvideHandler = proc(d: MockDiscovery, cid: Cid) {.async.} = + .publishBlockProvideHandler = proc( + d: MockDiscovery, + cid: Cid + ) {.async: (handleException: true).} = check manifestBlock.cid == cid advertised.complete(cid) @@ -162,7 +165,10 @@ asyncchecksuite "Block Advertising and Discovery": )) blockDiscovery.findBlockProvidersHandler = - proc(d: MockDiscovery, cid: Cid): Future[seq[SignedPeerRecord]] = + proc( + d: MockDiscovery, + cid: Cid + ): Future[seq[SignedPeerRecord]] {.async: (handleException: true).} = check false await engine.start() # fire up discovery loop diff --git a/tests/codex/blockexchange/discovery/testdiscoveryengine.nim b/tests/codex/blockexchange/discovery/testdiscoveryengine.nim index 7b599573..cdaedcc3 100644 --- a/tests/codex/blockexchange/discovery/testdiscoveryengine.nim +++ b/tests/codex/blockexchange/discovery/testdiscoveryengine.nim @@ -2,7 +2,7 @@ import std/sequtils import std/sugar import std/tables -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/chronos @@ -100,7 +100,10 @@ asyncchecksuite "Test Discovery Engine": want = newFuture[void]() blockDiscovery.findBlockProvidersHandler = - proc(d: MockDiscovery, cid: Cid): Future[seq[SignedPeerRecord]] {.async, gcsafe.} = + proc( + d: MockDiscovery, + cid: Cid + ): Future[seq[SignedPeerRecord]] {.async: (handleException: true), gcsafe.} = check cid == blocks[0].cid if not want.finished: want.complete() @@ -123,7 +126,10 @@ asyncchecksuite "Test Discovery Engine": have = newFuture[void]() blockDiscovery.publishBlockProvideHandler = - proc(d: MockDiscovery, cid: Cid) {.async, gcsafe.} = + proc( + d: MockDiscovery, + cid: Cid + ) {.async: (handleException: true), gcsafe.} = check cid == blocks[0].cid if not have.finished: have.complete() @@ -147,7 +153,10 @@ asyncchecksuite "Test Discovery Engine": want = newAsyncEvent() blockDiscovery.findBlockProvidersHandler = - proc(d: MockDiscovery, cid: Cid): Future[seq[SignedPeerRecord]] {.async, gcsafe.} = + proc( + d: MockDiscovery, + cid: Cid + ): Future[seq[SignedPeerRecord]] {.async: (handleException: true), gcsafe.} = check cid == blocks[0].cid check peerStore.len < minPeers @@ -184,8 +193,10 @@ asyncchecksuite "Test Discovery Engine": count = 0 blockDiscovery.findBlockProvidersHandler = - proc(d: MockDiscovery, cid: Cid): - Future[seq[SignedPeerRecord]] {.gcsafe, async.} = + proc( + d: MockDiscovery, + cid: Cid + ): Future[seq[SignedPeerRecord]] {.gcsafe, async: (handleException: true).} = check cid == blocks[0].cid if count > 0: check false @@ -218,7 +229,10 @@ asyncchecksuite "Test Discovery Engine": count = 0 blockDiscovery.publishBlockProvideHandler = - proc(d: MockDiscovery, cid: Cid) {.async, gcsafe.} = + proc( + d: MockDiscovery, + cid: Cid + ) {.async: (handleException: true), gcsafe.} = check cid == blocks[0].cid if count > 0: check false diff --git a/tests/codex/blockexchange/engine/testblockexc.nim b/tests/codex/blockexchange/engine/testblockexc.nim index e1a8fef3..2d927796 100644 --- a/tests/codex/blockexchange/engine/testblockexc.nim +++ b/tests/codex/blockexchange/engine/testblockexc.nim @@ -1,7 +1,7 @@ import std/sequtils import std/algorithm -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/chronos import pkg/stew/byteutils diff --git a/tests/codex/blockexchange/engine/testengine.nim b/tests/codex/blockexchange/engine/testengine.nim index 5c960bb0..d9172442 100644 --- a/tests/codex/blockexchange/engine/testengine.nim +++ b/tests/codex/blockexchange/engine/testengine.nim @@ -3,7 +3,7 @@ import std/random import std/algorithm import pkg/stew/byteutils -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/chronos import pkg/libp2p/errors import pkg/libp2p/routing_record @@ -60,8 +60,8 @@ asyncchecksuite "NetworkStore engine basic": cancel: bool = false, wantType: WantType = WantType.WantHave, full: bool = false, - sendDontHave: bool = false) {.gcsafe, async.} = - check addresses.mapIt($it.cidOrTreeCid).sorted == blocks.mapIt( $it.cid ).sorted + sendDontHave: bool = false) {.gcsafe, async: (handleException: true).} = + check addresses.mapIt($it.cidOrTreeCid).sorted == blocks.mapIt($it.cid).sorted done.complete() let @@ -94,7 +94,7 @@ asyncchecksuite "NetworkStore engine basic": test "Should send account to new peers": let pricing = Pricing.example - proc sendAccount(peer: PeerId, account: Account) {.gcsafe, async.} = + proc sendAccount(peer: PeerId, account: Account) {.gcsafe, async: (handleException: true).} = check account.address == pricing.address done.complete() @@ -189,7 +189,7 @@ asyncchecksuite "NetworkStore engine handlers": blocks.mapIt( it.cid ), wantType = WantType.WantBlock) # only `wantBlock` are stored in `peerWants` - proc handler() {.async.} = + proc handler() {.async: (handleException: true).} = let ctx = await engine.taskQueue.pop() check ctx.id == peerId # only `wantBlock` scheduled @@ -204,7 +204,7 @@ asyncchecksuite "NetworkStore engine handlers": done = newFuture[void]() wantList = makeWantList(blocks.mapIt( it.cid )) - proc sendPresence(peerId: PeerId, presence: seq[BlockPresence]) {.gcsafe, async.} = + proc sendPresence(peerId: PeerId, presence: seq[BlockPresence]) {.gcsafe, async: (handleException: true).} = check presence.mapIt( it.address ) == wantList.entries.mapIt( it.address ) done.complete() @@ -226,7 +226,7 @@ asyncchecksuite "NetworkStore engine handlers": blocks.mapIt( it.cid ), sendDontHave = true) - proc sendPresence(peerId: PeerId, presence: seq[BlockPresence]) {.gcsafe, async.} = + proc sendPresence(peerId: PeerId, presence: seq[BlockPresence]) {.gcsafe, async: (handleException: true).} = check presence.mapIt( it.address ) == wantList.entries.mapIt( it.address ) for p in presence: check: @@ -248,7 +248,7 @@ asyncchecksuite "NetworkStore engine handlers": blocks.mapIt( it.cid ), sendDontHave = true) - proc sendPresence(peerId: PeerId, presence: seq[BlockPresence]) {.gcsafe, async.} = + proc sendPresence(peerId: PeerId, presence: seq[BlockPresence]) {.gcsafe, async: (handleException: true).} = for p in presence: if p.address.cidOrTreeCid != blocks[0].cid and p.address.cidOrTreeCid != blocks[1].cid: check p.`type` == BlockPresenceType.DontHave @@ -295,7 +295,7 @@ asyncchecksuite "NetworkStore engine handlers": engine.network = BlockExcNetwork( request: BlockExcRequest( - sendPayment: proc(receiver: PeerId, payment: SignedState) {.gcsafe, async.} = + sendPayment: proc(receiver: PeerId, payment: SignedState) {.gcsafe, async: (handleException: true).} = let amount = blocks.mapIt( @@ -421,7 +421,7 @@ asyncchecksuite "Task Handler": test "Should send want-blocks in priority order": proc sendBlocksDelivery( id: PeerId, - blocksDelivery: seq[BlockDelivery]) {.gcsafe, async.} = + blocksDelivery: seq[BlockDelivery]) {.gcsafe, async: (handleException: true).} = check blocksDelivery.len == 2 check: blocksDelivery[1].address == blocks[0].address @@ -458,7 +458,7 @@ asyncchecksuite "Task Handler": let missing = @[Block.new("missing".toBytes).tryGet()] let price = (!engine.pricing).price - proc sendPresence(id: PeerId, presence: seq[BlockPresence]) {.gcsafe, async.} = + proc sendPresence(id: PeerId, presence: seq[BlockPresence]) {.gcsafe, async: (handleException: true).} = check presence.mapIt(!Presence.init(it)) == @[ Presence(address: present[0].address, have: true, price: price), Presence(address: present[1].address, have: true, price: price), diff --git a/tests/codex/blockexchange/protobuf/testpayments.nim b/tests/codex/blockexchange/protobuf/testpayments.nim index 9760d6c8..ca0cde1c 100644 --- a/tests/codex/blockexchange/protobuf/testpayments.nim +++ b/tests/codex/blockexchange/protobuf/testpayments.nim @@ -1,4 +1,4 @@ -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/chronos import pkg/stew/byteutils import ../../examples diff --git a/tests/codex/blockexchange/protobuf/testpresence.nim b/tests/codex/blockexchange/protobuf/testpresence.nim index 6011aeff..72997a8d 100644 --- a/tests/codex/blockexchange/protobuf/testpresence.nim +++ b/tests/codex/blockexchange/protobuf/testpresence.nim @@ -1,4 +1,4 @@ -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/chronos import pkg/codex/blockexchange/protobuf/presence @@ -7,7 +7,7 @@ import ../../helpers checksuite "block presence protobuf messages": - let + let cid = Cid.example address = BlockAddress(leaf: false, cid: cid) price = UInt256.example diff --git a/tests/codex/blockexchange/testnetwork.nim b/tests/codex/blockexchange/testnetwork.nim index eecf231a..12648e74 100644 --- a/tests/codex/blockexchange/testnetwork.nim +++ b/tests/codex/blockexchange/testnetwork.nim @@ -1,7 +1,7 @@ import std/sequtils import std/tables -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/chronos import pkg/codex/rng @@ -47,7 +47,8 @@ asyncchecksuite "Network - Handlers": discard await networkPeer.connect() test "Want List handler": - proc wantListHandler(peer: PeerId, wantList: WantList) {.gcsafe, async.} = + proc wantListHandler(peer: PeerId, wantList: WantList) {.gcsafe, + async: (handleException: true).} = # check that we got the correct amount of entries check wantList.entries.len == 4 @@ -74,7 +75,10 @@ asyncchecksuite "Network - Handlers": await done.wait(500.millis) test "Blocks Handler": - proc blocksDeliveryHandler(peer: PeerId, blocksDelivery: seq[BlockDelivery]) {.gcsafe, async.} = + proc blocksDeliveryHandler( + peer: PeerId, + blocksDelivery: seq[BlockDelivery] + ) {.gcsafe, async: (handleException: true).} = check blocks == blocksDelivery.mapIt(it.blk) done.complete() @@ -88,7 +92,7 @@ asyncchecksuite "Network - Handlers": test "Presence Handler": proc presenceHandler( peer: PeerId, - presence: seq[BlockPresence]) {.gcsafe, async.} = + presence: seq[BlockPresence]) {.gcsafe, async: (handleException: true).} = for b in blocks: check: b.address in presence @@ -110,7 +114,10 @@ asyncchecksuite "Network - Handlers": test "Handles account messages": let account = Account(address: EthAddress.example) - proc handleAccount(peer: PeerId, received: Account) {.gcsafe, async.} = + proc handleAccount( + peer: PeerId, + received: Account + ) {.gcsafe, async: (handleException: true).} = check received == account done.complete() @@ -124,7 +131,10 @@ asyncchecksuite "Network - Handlers": test "Handles payment messages": let payment = SignedState.example - proc handlePayment(peer: PeerId, received: SignedState) {.gcsafe, async.} = + proc handlePayment( + peer: PeerId, + received: SignedState + ) {.gcsafe, async: (handleException: true).} = check received == payment done.complete() @@ -177,7 +187,10 @@ asyncchecksuite "Network - Senders": switch2.stop()) test "Send want list": - proc wantListHandler(peer: PeerId, wantList: WantList) {.gcsafe, async.} = + proc wantListHandler( + peer: PeerId, + wantList: WantList + ) {.gcsafe, async: (handleException: true).} = # check that we got the correct amount of entries check wantList.entries.len == 4 @@ -201,7 +214,10 @@ asyncchecksuite "Network - Senders": await done.wait(500.millis) test "send blocks": - proc blocksDeliveryHandler(peer: PeerId, blocksDelivery: seq[BlockDelivery]) {.gcsafe, async.} = + proc blocksDeliveryHandler( + peer: PeerId, + blocksDelivery: seq[BlockDelivery] + ) {.gcsafe, async: (handleException: true).} = check blocks == blocksDelivery.mapIt(it.blk) done.complete() @@ -215,7 +231,7 @@ asyncchecksuite "Network - Senders": test "send presence": proc presenceHandler( peer: PeerId, - precense: seq[BlockPresence]) {.gcsafe, async.} = + precense: seq[BlockPresence]) {.gcsafe, async: (handleException: true).} = for b in blocks: check: b.address in precense @@ -237,7 +253,10 @@ asyncchecksuite "Network - Senders": test "send account": let account = Account(address: EthAddress.example) - proc handleAccount(peer: PeerId, received: Account) {.gcsafe, async.} = + proc handleAccount( + peer: PeerId, + received: Account + ) {.gcsafe, async: (handleException: true).} = check received == account done.complete() @@ -249,7 +268,10 @@ asyncchecksuite "Network - Senders": test "send payment": let payment = SignedState.example - proc handlePayment(peer: PeerId, received: SignedState) {.gcsafe, async.} = + proc handlePayment( + peer: PeerId, + received: SignedState + ) {.gcsafe, async: (handleException: true).} = check received == payment done.complete() @@ -293,7 +315,10 @@ asyncchecksuite "Network - Test Limits": test "Concurrent Sends": let account = Account(address: EthAddress.example) network2.handlers.onAccount = - proc(peer: PeerId, received: Account) {.gcsafe, async.} = + proc( + peer: PeerId, + received: Account + ) {.gcsafe, async: (handleException: true).} = check false let fut = network1.send( diff --git a/tests/codex/blockexchange/testpeerctxstore.nim b/tests/codex/blockexchange/testpeerctxstore.nim index 868e0819..6d7a1af3 100644 --- a/tests/codex/blockexchange/testpeerctxstore.nim +++ b/tests/codex/blockexchange/testpeerctxstore.nim @@ -1,7 +1,7 @@ import std/sugar import std/sequtils +import std/unittest -import pkg/unittest2 import pkg/libp2p import pkg/codex/blockexchange/peers diff --git a/tests/codex/blockexchange/testpendingblocks.nim b/tests/codex/blockexchange/testpendingblocks.nim index 21637515..6d603608 100644 --- a/tests/codex/blockexchange/testpendingblocks.nim +++ b/tests/codex/blockexchange/testpendingblocks.nim @@ -2,7 +2,7 @@ import std/sequtils import std/algorithm import pkg/chronos -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/stew/byteutils import pkg/codex/blocktype as bt diff --git a/tests/codex/helpers/mockclock.nim b/tests/codex/helpers/mockclock.nim index ada449f9..d9c8e8cf 100644 --- a/tests/codex/helpers/mockclock.nim +++ b/tests/codex/helpers/mockclock.nim @@ -32,7 +32,7 @@ proc set*(clock: MockClock, time: SecondsSince1970) = proc advance*(clock: MockClock, seconds: int64) = clock.set(clock.time + seconds) -method now*(clock: MockClock): SecondsSince1970 = +method now*(clock: MockClock): SecondsSince1970 {.raises: [].} = clock.time method waitUntil*(clock: MockClock, time: SecondsSince1970) {.async.} = diff --git a/tests/codex/helpers/mockdiscovery.nim b/tests/codex/helpers/mockdiscovery.nim index 5d5e8132..f6ebdf7f 100644 --- a/tests/codex/helpers/mockdiscovery.nim +++ b/tests/codex/helpers/mockdiscovery.nim @@ -16,13 +16,13 @@ import pkg/contractabi/address as ca type MockDiscovery* = ref object of Discovery findBlockProvidersHandler*: proc(d: MockDiscovery, cid: Cid): - Future[seq[SignedPeerRecord]] {.gcsafe.} + Future[seq[SignedPeerRecord]] {.gcsafe, raises: [].} publishBlockProvideHandler*: proc(d: MockDiscovery, cid: Cid): - Future[void] {.gcsafe.} + Future[void] {.gcsafe, raises: [].} findHostProvidersHandler*: proc(d: MockDiscovery, host: ca.Address): - Future[seq[SignedPeerRecord]] {.gcsafe.} + Future[seq[SignedPeerRecord]] {.gcsafe, raises: [].} publishHostProvideHandler*: proc(d: MockDiscovery, host: ca.Address): - Future[void] {.gcsafe.} + Future[void] {.gcsafe, raises: [].} proc new*(T: type MockDiscovery): MockDiscovery = MockDiscovery() @@ -32,7 +32,7 @@ proc findPeer*( peerId: PeerId ): Future[?PeerRecord] {.async.} = ## mock find a peer - always return none - ## + ## return none(PeerRecord) method find*( diff --git a/tests/codex/sales/states/testfilled.nim b/tests/codex/sales/states/testfilled.nim index 92a004a3..15ed7315 100644 --- a/tests/codex/sales/states/testfilled.nim +++ b/tests/codex/sales/states/testfilled.nim @@ -1,4 +1,4 @@ -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/questionable/results import pkg/codex/clock diff --git a/tests/codex/sales/states/testinitialproving.nim b/tests/codex/sales/states/testinitialproving.nim index e083b68b..2429e62d 100644 --- a/tests/codex/sales/states/testinitialproving.nim +++ b/tests/codex/sales/states/testinitialproving.nim @@ -1,4 +1,4 @@ -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/questionable import pkg/chronos import pkg/codex/contracts/requests diff --git a/tests/codex/sales/states/testproving.nim b/tests/codex/sales/states/testproving.nim index 3658b06f..70a2cd73 100644 --- a/tests/codex/sales/states/testproving.nim +++ b/tests/codex/sales/states/testproving.nim @@ -1,4 +1,4 @@ -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/chronos import pkg/questionable import pkg/codex/contracts/requests diff --git a/tests/codex/sales/states/testsimulatedproving.nim b/tests/codex/sales/states/testsimulatedproving.nim index 164d4fdc..9262a3ea 100644 --- a/tests/codex/sales/states/testsimulatedproving.nim +++ b/tests/codex/sales/states/testsimulatedproving.nim @@ -1,4 +1,4 @@ -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/chronos import pkg/questionable import pkg/codex/contracts/requests diff --git a/tests/codex/sales/states/testunknown.nim b/tests/codex/sales/states/testunknown.nim index 7c8e275a..beb2b226 100644 --- a/tests/codex/sales/states/testunknown.nim +++ b/tests/codex/sales/states/testunknown.nim @@ -1,4 +1,4 @@ -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/codex/contracts/requests import pkg/codex/sales import pkg/codex/sales/salesagent diff --git a/tests/codex/sales/testreservations.nim b/tests/codex/sales/testreservations.nim index a6ab1b26..1f9e5577 100644 --- a/tests/codex/sales/testreservations.nim +++ b/tests/codex/sales/testreservations.nim @@ -3,7 +3,7 @@ import std/random import pkg/questionable import pkg/questionable/results import pkg/chronos -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/datastore import pkg/codex/stores diff --git a/tests/codex/sales/testsales.nim b/tests/codex/sales/testsales.nim index baa3fbc9..49ca567d 100644 --- a/tests/codex/sales/testsales.nim +++ b/tests/codex/sales/testsales.nim @@ -1,7 +1,7 @@ import std/sequtils import std/sugar import std/times -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/chronos import pkg/datastore import pkg/questionable @@ -14,6 +14,7 @@ import pkg/codex/sales/slotqueue import pkg/codex/stores/repostore import pkg/codex/blocktype as bt import pkg/codex/node +import pkg/codex/utils/asyncspawn import ../helpers import ../helpers/mockmarket import ../helpers/mockclock @@ -288,7 +289,7 @@ asyncchecksuite "Sales": slot: UInt256, onBatch: BatchProc): Future[?!void] {.async.} = let blk = bt.Block.new( @[1.byte] ).get - onBatch( blk.repeat(request.ask.slotSize.truncate(int)) ) + asyncSpawn onBatch( blk.repeat(request.ask.slotSize.truncate(int)) ) return success() createAvailability() @@ -302,7 +303,7 @@ asyncchecksuite "Sales": onBatch: BatchProc): Future[?!void] {.async.} = slotIndex = slot let blk = bt.Block.new( @[1.byte] ).get - onBatch(@[ blk ]) + asyncSpawn onBatch(@[ blk ]) return success() let sold = newFuture[void]() sales.onSale = proc(request: StorageRequest, slotIndex: UInt256) = diff --git a/tests/codex/sales/testsalesagent.nim b/tests/codex/sales/testsalesagent.nim index 48a4f9d9..90f1e98e 100644 --- a/tests/codex/sales/testsalesagent.nim +++ b/tests/codex/sales/testsalesagent.nim @@ -1,5 +1,5 @@ import std/times -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/chronos import pkg/codex/sales import pkg/codex/sales/salesagent diff --git a/tests/codex/sales/testslotqueue.nim b/tests/codex/sales/testslotqueue.nim index 18d1e429..67ea7eca 100644 --- a/tests/codex/sales/testslotqueue.nim +++ b/tests/codex/sales/testslotqueue.nim @@ -1,5 +1,6 @@ import std/sequtils -import pkg/asynctest +import pkg/asynctest/chronos/unittest +import pkg/chronicles import pkg/chronos import pkg/datastore import pkg/questionable diff --git a/tests/codex/stores/commonstoretests.nim b/tests/codex/stores/commonstoretests.nim index 13b18f50..46cb051b 100644 --- a/tests/codex/stores/commonstoretests.nim +++ b/tests/codex/stores/commonstoretests.nim @@ -3,7 +3,7 @@ import std/strutils import std/options import pkg/chronos -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/libp2p/multicodec import pkg/stew/byteutils import pkg/questionable diff --git a/tests/codex/stores/testcachestore.nim b/tests/codex/stores/testcachestore.nim index c6737ab3..e366a470 100644 --- a/tests/codex/stores/testcachestore.nim +++ b/tests/codex/stores/testcachestore.nim @@ -1,7 +1,7 @@ import std/strutils import pkg/chronos -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/stew/byteutils import pkg/questionable/results import pkg/codex/stores/cachestore diff --git a/tests/codex/stores/testkeyutils.nim b/tests/codex/stores/testkeyutils.nim index ccf368ea..6e5e171b 100644 --- a/tests/codex/stores/testkeyutils.nim +++ b/tests/codex/stores/testkeyutils.nim @@ -10,7 +10,7 @@ import std/random import std/sequtils import pkg/chronos -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/questionable import pkg/questionable/results import pkg/codex/blocktype as bt diff --git a/tests/codex/stores/testmaintenance.nim b/tests/codex/stores/testmaintenance.nim index 18806721..da6aff54 100644 --- a/tests/codex/stores/testmaintenance.nim +++ b/tests/codex/stores/testmaintenance.nim @@ -8,7 +8,7 @@ ## those terms. import pkg/chronos -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/questionable/results import pkg/codex/blocktype as bt import pkg/codex/stores/repostore diff --git a/tests/codex/stores/testrepostore.nim b/tests/codex/stores/testrepostore.nim index fabe3444..0677cc95 100644 --- a/tests/codex/stores/testrepostore.nim +++ b/tests/codex/stores/testrepostore.nim @@ -6,7 +6,7 @@ import pkg/questionable import pkg/questionable/results import pkg/chronos -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/stew/byteutils import pkg/stew/endians2 import pkg/datastore diff --git a/tests/codex/testasyncheapqueue.nim b/tests/codex/testasyncheapqueue.nim index 8df3e44d..a2ae5069 100644 --- a/tests/codex/testasyncheapqueue.nim +++ b/tests/codex/testasyncheapqueue.nim @@ -1,5 +1,5 @@ import pkg/chronos -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/stew/results import pkg/codex/utils/asyncheapqueue diff --git a/tests/codex/testasyncstreamwrapper.nim b/tests/codex/testasyncstreamwrapper.nim index 90aac77f..b55843d1 100644 --- a/tests/codex/testasyncstreamwrapper.nim +++ b/tests/codex/testasyncstreamwrapper.nim @@ -1,4 +1,4 @@ -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/chronos import pkg/chronos/transports/stream import pkg/chronos/transports/common diff --git a/tests/codex/testchunking.nim b/tests/codex/testchunking.nim index e8186c01..fca776ff 100644 --- a/tests/codex/testchunking.nim +++ b/tests/codex/testchunking.nim @@ -1,5 +1,5 @@ -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/stew/byteutils import pkg/codex/chunker import pkg/codex/logutils diff --git a/tests/codex/testerasure.nim b/tests/codex/testerasure.nim index 0c7e08a5..5d7e3e5a 100644 --- a/tests/codex/testerasure.nim +++ b/tests/codex/testerasure.nim @@ -1,7 +1,7 @@ import std/sequtils import std/sugar -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/chronos import pkg/datastore import pkg/questionable/results @@ -35,7 +35,9 @@ suite "Erasure encode/decode": erasure = Erasure.new(store, leoEncoderProvider, leoDecoderProvider) manifest = await storeDataGetManifest(store, chunker) - proc encode(buffers, parity: int): Future[Manifest] {.async.} = + proc encode( + buffers, parity: int): Future[Manifest] {.async: + (handleException: true).} = let encoded = (await erasure.encode( manifest, diff --git a/tests/codex/testmanifest.nim b/tests/codex/testmanifest.nim index 184bcdd0..f79ffab0 100644 --- a/tests/codex/testmanifest.nim +++ b/tests/codex/testmanifest.nim @@ -2,7 +2,9 @@ import std/sequtils import pkg/chronos import pkg/questionable/results -import pkg/asynctest +import pkg/asynctest/chronos/unittest +import pkg/stew/byteutils + import pkg/codex/chunker import pkg/codex/blocktype as bt import pkg/codex/manifest diff --git a/tests/codex/testpurchasing.nim b/tests/codex/testpurchasing.nim index 3efe92c4..f7778029 100644 --- a/tests/codex/testpurchasing.nim +++ b/tests/codex/testpurchasing.nim @@ -1,5 +1,5 @@ import std/times -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/chronos import pkg/stint import pkg/codex/purchasing diff --git a/tests/codex/teststorestream.nim b/tests/codex/teststorestream.nim index 362f1467..00eed526 100644 --- a/tests/codex/teststorestream.nim +++ b/tests/codex/teststorestream.nim @@ -1,5 +1,5 @@ import pkg/chronos -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/questionable/results import ./helpers diff --git a/tests/codex/testvalidation.nim b/tests/codex/testvalidation.nim index 9891704d..4f8d9d4a 100644 --- a/tests/codex/testvalidation.nim +++ b/tests/codex/testvalidation.nim @@ -1,4 +1,4 @@ -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/chronos import codex/validation diff --git a/tests/codex/utils/testasyncstatemachine.nim b/tests/codex/utils/testasyncstatemachine.nim index bd6b355d..23e0489e 100644 --- a/tests/codex/utils/testasyncstatemachine.nim +++ b/tests/codex/utils/testasyncstatemachine.nim @@ -1,4 +1,4 @@ -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/questionable import pkg/chronos import pkg/upraises @@ -22,7 +22,8 @@ method run(state: State1, machine: Machine): Future[?State] {.async.} = inc runs[0] return some State(State2.new()) -method run(state: State2, machine: Machine): Future[?State] {.async.} = +method run(state: State2, + machine: Machine): Future[?State] {.async: (handleException: true).} = inc runs[1] try: await sleepAsync(1.hours) diff --git a/tests/codex/utils/testthen.nim b/tests/codex/utils/testthen.nim index 0b73d9ef..3d388446 100644 --- a/tests/codex/utils/testthen.nim +++ b/tests/codex/utils/testthen.nim @@ -1,4 +1,4 @@ -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/chronos import pkg/questionable import pkg/questionable/results diff --git a/tests/codex/utils/testtimer.nim b/tests/codex/utils/testtimer.nim index d09213ad..e3549903 100644 --- a/tests/codex/utils/testtimer.nim +++ b/tests/codex/utils/testtimer.nim @@ -8,7 +8,7 @@ ## those terms. import pkg/chronos -import pkg/asynctest +import pkg/asynctest/chronos/unittest import codex/utils/timer import ../helpers diff --git a/tests/codex/utils/testtrackedfutures.nim b/tests/codex/utils/testtrackedfutures.nim index 4e3937e5..4b0cf0b9 100644 --- a/tests/codex/utils/testtrackedfutures.nim +++ b/tests/codex/utils/testtrackedfutures.nim @@ -1,4 +1,4 @@ -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/chronos import codex/utils/trackedfutures import ../helpers diff --git a/tests/contracts/testDeployment.nim b/tests/contracts/testDeployment.nim index 525d10ee..81c6c0bd 100644 --- a/tests/contracts/testDeployment.nim +++ b/tests/contracts/testDeployment.nim @@ -1,4 +1,4 @@ -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/ethers import codex/contracts/deployment import codex/conf diff --git a/tests/ethertest.nim b/tests/ethertest.nim index 5c620310..ed26499e 100644 --- a/tests/ethertest.nim +++ b/tests/ethertest.nim @@ -1,5 +1,5 @@ - import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/ethers import ./checktest diff --git a/tests/helpers/multisetup.nim b/tests/helpers/multisetup.nim index 7a0ea4c3..781b0062 100644 --- a/tests/helpers/multisetup.nim +++ b/tests/helpers/multisetup.nim @@ -2,8 +2,9 @@ import pkg/chronos # Allow multiple setups and teardowns in a test suite template asyncmultisetup* = - var setups: seq[proc: Future[void] {.gcsafe.}] - var teardowns: seq[proc: Future[void] {.gcsafe.}] + var setups: seq[proc: Future[void].Raising([AsyncExceptionError]) {.gcsafe.}] + var teardowns: seq[ + proc: Future[void].Raising([AsyncExceptionError]) {.gcsafe.}] setup: for setup in setups: @@ -14,10 +15,12 @@ template asyncmultisetup* = await teardown() template setup(setupBody) {.inject, used.} = - setups.add(proc {.async.} = setupBody) + setups.add(proc {.async: ( + handleException: true, raises: [AsyncExceptionError]).} = setupBody) template teardown(teardownBody) {.inject, used.} = - teardowns.insert(proc {.async.} = teardownBody) + teardowns.insert(proc {.async: ( + handleException: true, raises: [AsyncExceptionError]).} = teardownBody) template multisetup* = var setups: seq[proc() {.gcsafe.}] @@ -32,7 +35,8 @@ template multisetup* = teardown() template setup(setupBody) {.inject, used.} = - setups.add(proc = setupBody) + let setupProc = proc = setupBody + setups.add(setupProc) template teardown(teardownBody) {.inject, used.} = teardowns.insert(proc = teardownBody) diff --git a/tests/testTaiko.nim b/tests/testTaiko.nim index 137a48fd..54ac99ee 100644 --- a/tests/testTaiko.nim +++ b/tests/testTaiko.nim @@ -2,7 +2,7 @@ import std/times import std/os import std/json import std/tempfiles -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/chronos import pkg/stint import pkg/questionable diff --git a/vendor/asynctest b/vendor/asynctest index fe1a34ca..8e2f4e73 160000 --- a/vendor/asynctest +++ b/vendor/asynctest @@ -1 +1 @@ -Subproject commit fe1a34caf572b05f8bdba3b650f1871af9fce31e +Subproject commit 8e2f4e73b97123be0f0041c129942b32df23ecb1