mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-27 06:01:48 +02:00
protofsm: add CustomPollInterval for mocking purposes
Adding this makes a state machine easier to unit test, as the caller can specify a custom polling interval.
This commit is contained in:
@@ -178,6 +178,10 @@ type StateMachineCfg[Event any, Env Environment] struct {
|
|||||||
// MsgMapper is an optional message mapper that can be used to map
|
// MsgMapper is an optional message mapper that can be used to map
|
||||||
// normal wire messages into FSM events.
|
// normal wire messages into FSM events.
|
||||||
MsgMapper fn.Option[MsgMapper[Event]]
|
MsgMapper fn.Option[MsgMapper[Event]]
|
||||||
|
|
||||||
|
// CustomPollInterval is an optional custom poll interval that can be
|
||||||
|
// used to set a quicker interval for tests.
|
||||||
|
CustomPollInterval fn.Option[time.Duration]
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewStateMachine creates a new state machine given a set of daemon adapters,
|
// NewStateMachine creates a new state machine given a set of daemon adapters,
|
||||||
@@ -373,7 +377,9 @@ func (s *StateMachine[Event, Env]) executeDaemonEvent( //nolint:funlen
|
|||||||
go func() {
|
go func() {
|
||||||
defer s.wg.Done()
|
defer s.wg.Done()
|
||||||
|
|
||||||
predicateTicker := time.NewTicker(pollInterval)
|
predicateTicker := time.NewTicker(
|
||||||
|
s.cfg.CustomPollInterval.UnwrapOr(pollInterval),
|
||||||
|
)
|
||||||
defer predicateTicker.Stop()
|
defer predicateTicker.Stop()
|
||||||
|
|
||||||
log.Infof("FSM(%v): waiting for send predicate to "+
|
log.Infof("FSM(%v): waiting for send predicate to "+
|
||||||
|
Reference in New Issue
Block a user