Skip to content

Commit

Permalink
Fixes race condition in initial-proving tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benbierens committed Nov 27, 2024
1 parent 2124996 commit 672de25
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 3 additions & 0 deletions tests/codex/helpers/mockclock.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 2 additions & 4 deletions tests/codex/sales/states/testinitialproving.nim
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ asyncchecksuite "sales state 'initialproving'":
state = SaleInitialProving.new()

proc allowProofToStart {.async.} =
# wait until we're in initialproving state
await sleepAsync(10.millis)
# it won't start proving until the next period
await clock.advanceToNextPeriod(market)

Expand All @@ -59,7 +57,7 @@ asyncchecksuite "sales state 'initialproving'":

test "waits for the beginning of the period to get the challenge":
let future = state.run(agent)
await sleepAsync(10.millis)
check eventually clock.isWaiting
check not future.finished
await allowProofToStart()
discard await future
Expand All @@ -68,7 +66,7 @@ asyncchecksuite "sales state 'initialproving'":
market.proofPointer = 250
let future = state.run(agent)
await allowProofToStart()
await sleepAsync(10.millis)
check eventually clock.isWaiting
check not future.finished
market.proofPointer = 100
await allowProofToStart()
Expand Down

0 comments on commit 672de25

Please sign in to comment.