From d805c0fc3c1c244c5cee39a40dcc05f270c0dada Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 29 Feb 2024 16:08:54 -0600 Subject: [PATCH] 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. --- protofsm/state_machine.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/protofsm/state_machine.go b/protofsm/state_machine.go index 2fb661c9c..71cf54dd7 100644 --- a/protofsm/state_machine.go +++ b/protofsm/state_machine.go @@ -178,6 +178,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, @@ -373,7 +377,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 "+