Skip to content

Commit

Permalink
Review comments by Eric. Also replaced two more sleeps with check-eve…
Browse files Browse the repository at this point in the history
…ntually
  • Loading branch information
benbierens committed Nov 26, 2024
1 parent 478de31 commit 08a1900
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
3 changes: 0 additions & 3 deletions tests/codex/helpers/mockclock.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 10 additions & 4 deletions tests/codex/sales/testsales.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 08a1900

Please sign in to comment.