Skip to content

Commit fb81d3e

Browse files
committed
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.
1 parent 9305fd3 commit fb81d3e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

protofsm/state_machine.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ type StateMachineCfg[Event any, Env Environment] struct {
184184
// MsgMapper is an optional message mapper that can be used to map
185185
// normal wire messages into FSM events.
186186
MsgMapper fn.Option[MsgMapper[Event]]
187+
188+
// CustomPollInterval is an optional custom poll interval that can be
189+
// used to set a quicker interval for tests.
190+
CustomPollInterval fn.Option[time.Duration]
187191
}
188192

189193
// NewStateMachine creates a new state machine given a set of daemon adapters,
@@ -387,7 +391,9 @@ func (s *StateMachine[Event, Env]) executeDaemonEvent( //nolint:funlen
387391
go func() {
388392
defer s.wg.Done()
389393

390-
predicateTicker := time.NewTicker(pollInterval)
394+
predicateTicker := time.NewTicker(
395+
s.cfg.CustomPollInterval.UnwrapOr(pollInterval),
396+
)
391397
defer predicateTicker.Stop()
392398

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

0 commit comments

Comments
 (0)