Fixes race condition in initial-proving tests (#1007)

This commit is contained in:
Ben Bierens 2024-12-04 09:56:53 +01:00 committed by GitHub
parent 0707446cdd
commit 63e54d135c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 4 deletions

View File

@ -40,3 +40,6 @@ method waitUntil*(clock: MockClock, time: SecondsSince1970) {.async.} =
let future = newFuture[void]() let future = newFuture[void]()
clock.waiting.add(Waiting(until: time, future: future)) clock.waiting.add(Waiting(until: time, future: future))
await future await future
proc isWaiting*(clock: MockClock): bool =
clock.waiting.len > 0

View File

@ -44,8 +44,6 @@ asyncchecksuite "sales state 'initialproving'":
state = SaleInitialProving.new() state = SaleInitialProving.new()
proc allowProofToStart {.async.} = proc allowProofToStart {.async.} =
# wait until we're in initialproving state
await sleepAsync(10.millis)
# it won't start proving until the next period # it won't start proving until the next period
await clock.advanceToNextPeriod(market) await clock.advanceToNextPeriod(market)
@ -59,7 +57,7 @@ asyncchecksuite "sales state 'initialproving'":
test "waits for the beginning of the period to get the challenge": test "waits for the beginning of the period to get the challenge":
let future = state.run(agent) let future = state.run(agent)
await sleepAsync(10.millis) check eventually clock.isWaiting
check not future.finished check not future.finished
await allowProofToStart() await allowProofToStart()
discard await future discard await future
@ -68,7 +66,7 @@ asyncchecksuite "sales state 'initialproving'":
market.proofPointer = 250 market.proofPointer = 250
let future = state.run(agent) let future = state.run(agent)
await allowProofToStart() await allowProofToStart()
await sleepAsync(10.millis) check eventually clock.isWaiting
check not future.finished check not future.finished
market.proofPointer = 100 market.proofPointer = 100
await allowProofToStart() await allowProofToStart()