Skip to content

Commit d805c0f

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 35ea05d commit d805c0f

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
@@ -178,6 +178,10 @@ type StateMachineCfg[Event any, Env Environment] struct {
178178
// MsgMapper is an optional message mapper that can be used to map
179179
// normal wire messages into FSM events.
180180
MsgMapper fn.Option[MsgMapper[Event]]
181+
182+
// CustomPollInterval is an optional custom poll interval that can be
183+
// used to set a quicker interval for tests.
184+
CustomPollInterval fn.Option[time.Duration]
181185
}
182186

183187
// NewStateMachine creates a new state machine given a set of daemon adapters,
@@ -373,7 +377,9 @@ func (s *StateMachine[Event, Env]) executeDaemonEvent( //nolint:funlen
373377
go func() {
374378
defer s.wg.Done()
375379

376-
predicateTicker := time.NewTicker(pollInterval)
380+
predicateTicker := time.NewTicker(
381+
s.cfg.CustomPollInterval.UnwrapOr(pollInterval),
382+
)
377383
defer predicateTicker.Stop()
378384

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

0 commit comments

Comments
 (0)