From 47c229311e817e599e9ed9080a2fea784cbbf878 Mon Sep 17 00:00:00 2001 From: benbierens Date: Thu, 21 Nov 2024 13:41:20 +0100 Subject: [PATCH 1/2] Adds isWaiting to mockClock to remove sleep in testsales --- tests/codex/helpers/mockclock.nim | 3 +++ tests/codex/sales/testsales.nim | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/codex/helpers/mockclock.nim b/tests/codex/helpers/mockclock.nim index ada449f90..75a251c9e 100644 --- a/tests/codex/helpers/mockclock.nim +++ b/tests/codex/helpers/mockclock.nim @@ -40,3 +40,6 @@ method waitUntil*(clock: MockClock, time: SecondsSince1970) {.async.} = let future = newFuture[void]() clock.waiting.add(Waiting(until: time, future: future)) await future + +proc isWaiting*(clock: MockClock): bool = + clock.waiting.len > 0 diff --git a/tests/codex/sales/testsales.nim b/tests/codex/sales/testsales.nim index 3d142d164..b66d973f1 100644 --- a/tests/codex/sales/testsales.nim +++ b/tests/codex/sales/testsales.nim @@ -190,7 +190,7 @@ asyncchecksuite "Sales": proc allowRequestToStart {.async.} = # wait until we're in initialproving state - await sleepAsync(10.millis) + check eventually clock.isWaiting # it won't start proving until the next period await clock.advanceToNextPeriod(market) From 08a1900fac2310c3bda0ec128badcfb927d8d996 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 26 Nov 2024 10:15:45 +0100 Subject: [PATCH 2/2] Review comments by Eric. Also replaced two more sleeps with check-eventually --- tests/codex/helpers/mockclock.nim | 3 --- tests/codex/sales/testsales.nim | 14 ++++++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/codex/helpers/mockclock.nim b/tests/codex/helpers/mockclock.nim index 75a251c9e..ada449f90 100644 --- a/tests/codex/helpers/mockclock.nim +++ b/tests/codex/helpers/mockclock.nim @@ -40,6 +40,3 @@ method waitUntil*(clock: MockClock, time: SecondsSince1970) {.async.} = let future = newFuture[void]() clock.waiting.add(Waiting(until: time, future: future)) await future - -proc isWaiting*(clock: MockClock): bool = - clock.waiting.len > 0 diff --git a/tests/codex/sales/testsales.nim b/tests/codex/sales/testsales.nim index b66d973f1..b71c0531a 100644 --- a/tests/codex/sales/testsales.nim +++ b/tests/codex/sales/testsales.nim @@ -13,6 +13,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/asyncstatemachine import ../../asynctest import ../helpers import ../helpers/mockmarket @@ -188,9 +189,14 @@ asyncchecksuite "Sales": await repoTmp.destroyDb() await metaTmp.destroyDb() + proc isInState(idx: int, state: string): Future[bool] {.async.} = + proc description(state: State): string = + $state + check eventually sales.agents.len > idx + sales.agents[idx].query(description) == state.some + proc allowRequestToStart {.async.} = - # wait until we're in initialproving state - check eventually clock.isWaiting + check eventually (await isInState(0, "SaleInitialProving")) # it won't start proving until the next period await clock.advanceToNextPeriod(market) @@ -291,7 +297,7 @@ asyncchecksuite "Sales": test "items in queue are readded (and marked seen) once ignored": await market.requestStorage(request) let items = SlotQueueItem.init(request) - await sleepAsync(10.millis) # queue starts paused, allow items to be added to the queue + check eventually queue.len > 0 # queue starts paused, allow items to be added to the queue check eventually queue.paused # The first processed item will be will have been re-pushed with `seen = # true`. Then, once this item is processed by the queue, its 'seen' flag @@ -311,7 +317,7 @@ asyncchecksuite "Sales": createAvailability() # enough to fill a single slot await market.requestStorage(request) let items = SlotQueueItem.init(request) - await sleepAsync(10.millis) # queue starts paused, allow items to be added to the queue + check eventually queue.len > 0 # queue starts paused, allow items to be added to the queue check eventually queue.paused # The first processed item/slot will be filled (eventually). Subsequent # items will be processed and eventually re-pushed with `seen = true`. Once