fix integration test
- When a state's run was cancelled, it was being caught as an error due to catching all CatchableErrors. This caused a state transition to SaleErrored, however cancellation of run was not actually an error. Handling this correctly fixed the issue. - Stopping of the clock was moved to after `HostInteractions` (sales) which avoided an assertion around getting time when the clock was not started.
This commit is contained in:
parent
b8ad3fdbe9
commit
be0d7102ab
|
@ -757,15 +757,15 @@ proc stop*(self: CodexNodeRef) {.async.} =
|
|||
if not self.discovery.isNil:
|
||||
await self.discovery.stop()
|
||||
|
||||
if not self.clock.isNil:
|
||||
await self.clock.stop()
|
||||
|
||||
if clientContracts =? self.contracts.client:
|
||||
await clientContracts.stop()
|
||||
|
||||
if hostContracts =? self.contracts.host:
|
||||
await hostContracts.stop()
|
||||
|
||||
if not self.clock.isNil:
|
||||
await self.clock.stop()
|
||||
|
||||
if validatorContracts =? self.contracts.validator:
|
||||
await validatorContracts.stop()
|
||||
|
||||
|
|
|
@ -67,23 +67,21 @@ proc run(machine: Machine, state: State) {.async.} =
|
|||
|
||||
proc scheduler(machine: Machine) {.async.} =
|
||||
var running: Future[void]
|
||||
try:
|
||||
while machine.started:
|
||||
let event = await machine.scheduled.get().track(machine)
|
||||
if next =? event(machine.state):
|
||||
if not running.isNil and not running.finished:
|
||||
await running.cancelAndWait()
|
||||
let fromState = if machine.state.isNil: "<none>" else: $machine.state
|
||||
machine.state = next
|
||||
debug "enter state", state = fromState & " => " & $machine.state
|
||||
running = machine.run(machine.state)
|
||||
running
|
||||
.track(machine)
|
||||
.catch((err: ref CatchableError) =>
|
||||
machine.schedule(machine.onError(err))
|
||||
)
|
||||
except CancelledError:
|
||||
discard
|
||||
while machine.started:
|
||||
let event = await machine.scheduled.get().track(machine)
|
||||
if next =? event(machine.state):
|
||||
if not running.isNil and not running.finished:
|
||||
trace "cancelling current state", state = $machine.state
|
||||
await running.cancelAndWait()
|
||||
let fromState = if machine.state.isNil: "<none>" else: $machine.state
|
||||
machine.state = next
|
||||
debug "enter state", state = fromState & " => " & $machine.state
|
||||
try:
|
||||
running = machine.run(machine.state).track(machine)
|
||||
except CancelledError as e:
|
||||
trace("run cancelled in state, swallowing", state = $machine.state)
|
||||
except CatchableError as e:
|
||||
machine.schedule(machine.onError(e))
|
||||
|
||||
proc start*(machine: Machine, initialState: State) =
|
||||
if machine.started:
|
||||
|
@ -93,12 +91,13 @@ proc start*(machine: Machine, initialState: State) =
|
|||
machine.scheduled = newAsyncQueue[Event]()
|
||||
|
||||
machine.started = true
|
||||
machine.scheduler()
|
||||
.track(machine)
|
||||
.catch((err: ref CatchableError) =>
|
||||
error("Error in scheduler", error = err.msg)
|
||||
)
|
||||
machine.schedule(Event.transition(machine.state, initialState))
|
||||
try:
|
||||
discard machine.scheduler().track(machine)
|
||||
machine.schedule(Event.transition(machine.state, initialState))
|
||||
except CancelledError as e:
|
||||
discard
|
||||
except CatchableError as e:
|
||||
error("Error in scheduler", error = e.msg)
|
||||
|
||||
proc stop*(machine: Machine) {.async.} =
|
||||
if not machine.started:
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 507ac6a4cc71cec9be7693fa393db4a49b52baf9
|
||||
Subproject commit d11c3cb1e69c9cce3ddb5c026594ac37ebed373b
|
Loading…
Reference in New Issue