Fixes race in testsales (#995)
* Adds isWaiting to mockClock to remove sleep in testsales * Review comments by Eric. Also replaced two more sleeps with check-eventually
This commit is contained in:
parent
5c6bbb0cee
commit
d47ce38894
|
@ -13,6 +13,7 @@ import pkg/codex/sales/slotqueue
|
||||||
import pkg/codex/stores/repostore
|
import pkg/codex/stores/repostore
|
||||||
import pkg/codex/blocktype as bt
|
import pkg/codex/blocktype as bt
|
||||||
import pkg/codex/node
|
import pkg/codex/node
|
||||||
|
import pkg/codex/utils/asyncstatemachine
|
||||||
import ../../asynctest
|
import ../../asynctest
|
||||||
import ../helpers
|
import ../helpers
|
||||||
import ../helpers/mockmarket
|
import ../helpers/mockmarket
|
||||||
|
@ -188,9 +189,14 @@ asyncchecksuite "Sales":
|
||||||
await repoTmp.destroyDb()
|
await repoTmp.destroyDb()
|
||||||
await metaTmp.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.} =
|
proc allowRequestToStart {.async.} =
|
||||||
# wait until we're in initialproving state
|
check eventually (await isInState(0, "SaleInitialProving"))
|
||||||
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)
|
||||||
|
|
||||||
|
@ -291,7 +297,7 @@ asyncchecksuite "Sales":
|
||||||
test "items in queue are readded (and marked seen) once ignored":
|
test "items in queue are readded (and marked seen) once ignored":
|
||||||
await market.requestStorage(request)
|
await market.requestStorage(request)
|
||||||
let items = SlotQueueItem.init(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
|
check eventually queue.paused
|
||||||
# The first processed item will be will have been re-pushed with `seen =
|
# 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
|
# 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
|
createAvailability() # enough to fill a single slot
|
||||||
await market.requestStorage(request)
|
await market.requestStorage(request)
|
||||||
let items = SlotQueueItem.init(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
|
check eventually queue.paused
|
||||||
# The first processed item/slot will be filled (eventually). Subsequent
|
# The first processed item/slot will be filled (eventually). Subsequent
|
||||||
# items will be processed and eventually re-pushed with `seen = true`. Once
|
# items will be processed and eventually re-pushed with `seen = true`. Once
|
||||||
|
|
Loading…
Reference in New Issue