Merge pull request #9311 from Roasbeef/protofsm-race-fix
protofsm: fix race in state machine executor tests
This commit is contained in:
1 file changed
+14
-9
@@ -251,14 +251,14 @@ func TestStateMachineOnInitDaemonEvent(t *testing.T) {
|
|||||||
// message adapter is called on start up.
|
// message adapter is called on start up.
|
||||||
adapters.On("SendMessages", *pub1, mock.Anything).Return(nil)
|
adapters.On("SendMessages", *pub1, mock.Anything).Return(nil)
|
||||||
|
|
||||||
stateMachine.Start()
|
|
||||||
defer stateMachine.Stop()
|
|
||||||
|
|
||||||
// As we're triggering internal events, we'll also subscribe to the set
|
// As we're triggering internal events, we'll also subscribe to the set
|
||||||
// of new states so we can assert as we go.
|
// of new states so we can assert as we go.
|
||||||
stateSub := stateMachine.RegisterStateEvents()
|
stateSub := stateMachine.RegisterStateEvents()
|
||||||
defer stateMachine.RemoveStateSub(stateSub)
|
defer stateMachine.RemoveStateSub(stateSub)
|
||||||
|
|
||||||
|
stateMachine.Start()
|
||||||
|
defer stateMachine.Stop()
|
||||||
|
|
||||||
// Assert that we go from the starting state to the final state. The
|
// Assert that we go from the starting state to the final state. The
|
||||||
// state machine should now also be on the final terminal state.
|
// state machine should now also be on the final terminal state.
|
||||||
expectedStates := []State[dummyEvents, *dummyEnv]{
|
expectedStates := []State[dummyEvents, *dummyEnv]{
|
||||||
@@ -292,14 +292,15 @@ func TestStateMachineInternalEvents(t *testing.T) {
|
|||||||
InitEvent: fn.None[DaemonEvent](),
|
InitEvent: fn.None[DaemonEvent](),
|
||||||
}
|
}
|
||||||
stateMachine := NewStateMachine(cfg)
|
stateMachine := NewStateMachine(cfg)
|
||||||
stateMachine.Start()
|
|
||||||
defer stateMachine.Stop()
|
|
||||||
|
|
||||||
// As we're triggering internal events, we'll also subscribe to the set
|
// As we're triggering internal events, we'll also subscribe to the set
|
||||||
// of new states so we can assert as we go.
|
// of new states so we can assert as we go.
|
||||||
stateSub := stateMachine.RegisterStateEvents()
|
stateSub := stateMachine.RegisterStateEvents()
|
||||||
defer stateMachine.RemoveStateSub(stateSub)
|
defer stateMachine.RemoveStateSub(stateSub)
|
||||||
|
|
||||||
|
stateMachine.Start()
|
||||||
|
defer stateMachine.Stop()
|
||||||
|
|
||||||
// For this transition, we'll send in the emitInternal event, which'll
|
// For this transition, we'll send in the emitInternal event, which'll
|
||||||
// send us back to the starting event, but emit an internal event.
|
// send us back to the starting event, but emit an internal event.
|
||||||
stateMachine.SendEvent(&emitInternal{})
|
stateMachine.SendEvent(&emitInternal{})
|
||||||
@@ -343,14 +344,15 @@ func TestStateMachineDaemonEvents(t *testing.T) {
|
|||||||
InitEvent: fn.None[DaemonEvent](),
|
InitEvent: fn.None[DaemonEvent](),
|
||||||
}
|
}
|
||||||
stateMachine := NewStateMachine(cfg)
|
stateMachine := NewStateMachine(cfg)
|
||||||
stateMachine.Start()
|
|
||||||
defer stateMachine.Stop()
|
|
||||||
|
|
||||||
// As we're triggering internal events, we'll also subscribe to the set
|
// As we're triggering internal events, we'll also subscribe to the set
|
||||||
// of new states so we can assert as we go.
|
// of new states so we can assert as we go.
|
||||||
stateSub := stateMachine.RegisterStateEvents()
|
stateSub := stateMachine.RegisterStateEvents()
|
||||||
defer stateMachine.RemoveStateSub(stateSub)
|
defer stateMachine.RemoveStateSub(stateSub)
|
||||||
|
|
||||||
|
stateMachine.Start()
|
||||||
|
defer stateMachine.Stop()
|
||||||
|
|
||||||
// As soon as we send in the daemon event, we expect the
|
// As soon as we send in the daemon event, we expect the
|
||||||
// disable+broadcast events to be processed, as they are unconditional.
|
// disable+broadcast events to be processed, as they are unconditional.
|
||||||
adapters.On(
|
adapters.On(
|
||||||
@@ -428,14 +430,17 @@ func TestStateMachineMsgMapper(t *testing.T) {
|
|||||||
MsgMapper: fn.Some[MsgMapper[dummyEvents]](dummyMapper),
|
MsgMapper: fn.Some[MsgMapper[dummyEvents]](dummyMapper),
|
||||||
}
|
}
|
||||||
stateMachine := NewStateMachine(cfg)
|
stateMachine := NewStateMachine(cfg)
|
||||||
stateMachine.Start()
|
|
||||||
defer stateMachine.Stop()
|
|
||||||
|
|
||||||
// As we're triggering internal events, we'll also subscribe to the set
|
// As we're triggering internal events, we'll also subscribe to the set
|
||||||
// of new states so we can assert as we go.
|
// of new states so we can assert as we go.
|
||||||
|
//
|
||||||
|
// We register before calling Start to ensure we don't miss any events.
|
||||||
stateSub := stateMachine.RegisterStateEvents()
|
stateSub := stateMachine.RegisterStateEvents()
|
||||||
defer stateMachine.RemoveStateSub(stateSub)
|
defer stateMachine.RemoveStateSub(stateSub)
|
||||||
|
|
||||||
|
stateMachine.Start()
|
||||||
|
defer stateMachine.Stop()
|
||||||
|
|
||||||
// First, we'll verify that the CanHandle method works as expected.
|
// First, we'll verify that the CanHandle method works as expected.
|
||||||
require.True(t, stateMachine.CanHandle(wireError))
|
require.True(t, stateMachine.CanHandle(wireError))
|
||||||
require.False(t, stateMachine.CanHandle(&lnwire.Init{}))
|
require.False(t, stateMachine.CanHandle(&lnwire.Init{}))
|
||||||
|
|||||||
Reference in new issue
Block a user