From 63e54d135c99c231badf3a60fefdc482100f3e27 Mon Sep 17 00:00:00 2001 From: Ben Bierens <39762930+benbierens@users.noreply.github.com> Date: Wed, 4 Dec 2024 09:56:53 +0100 Subject: [PATCH] Fixes race condition in initial-proving tests (#1007) --- tests/codex/helpers/mockclock.nim | 3 +++ tests/codex/sales/states/testinitialproving.nim | 6 ++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/codex/helpers/mockclock.nim b/tests/codex/helpers/mockclock.nim index ada449f9..75a251c9 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/states/testinitialproving.nim b/tests/codex/sales/states/testinitialproving.nim index 69355567..af12852b 100644 --- a/tests/codex/sales/states/testinitialproving.nim +++ b/tests/codex/sales/states/testinitialproving.nim @@ -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) @@ -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 @@ -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()