Skip to content

Commit

Permalink
protofsm: add CustomPollInterval for mocking purposes
Browse files Browse the repository at this point in the history
Adding this makes a state machine easier to unit test, as the caller can
specify a custom polling interval.
  • Loading branch information
Roasbeef committed Aug 16, 2024
1 parent 12e9e07 commit 383e192
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion protofsm/state_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ type StateMachineCfg[Event any, Env Environment] struct {
// MsgMapper is an optional message mapper that can be used to map
// normal wire messages into FSM events.
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,
Expand Down Expand Up @@ -387,7 +391,9 @@ func (s *StateMachine[Event, Env]) executeDaemonEvent( //nolint:funlen
go func() {
defer s.wg.Done()

predicateTicker := time.NewTicker(pollInterval)
predicateTicker := time.NewTicker(
s.cfg.CustomPollInterval.UnwrapOr(pollInterval),
)
defer predicateTicker.Stop()

log.Infof("FSM(%v): waiting for send predicate to "+
Expand Down

0 comments on commit 383e192

Please sign in to comment.