Skip to content

Commit 2fd1f77

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 7e7ef28 commit 2fd1f77

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
@@ -187,6 +187,10 @@ type StateMachineCfg[Event any, Env Environment] struct {
187187
// MsgMapper is an optional message mapper that can be used to map
188188
// normal wire messages into FSM events.
189189
MsgMapper fn.Option[MsgMapper[Event]]
190+
191+
// CustomPollInterval is an optional custom poll interval that can be
192+
// used to set a quicker interval for tests.
193+
CustomPollInterval fn.Option[time.Duration]
190194
}
191195

192196
// NewStateMachine creates a new state machine given a set of daemon adapters,
@@ -390,7 +394,9 @@ func (s *StateMachine[Event, Env]) executeDaemonEvent( //nolint:funlen
390394
go func() {
391395
defer s.wg.Done()
392396

393-
predicateTicker := time.NewTicker(pollInterval)
397+
predicateTicker := time.NewTicker(
398+
s.cfg.CustomPollInterval.UnwrapOr(pollInterval),
399+
)
394400
defer predicateTicker.Stop()
395401

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

0 commit comments

Comments
 (0)