@@ -104,6 +104,9 @@ type AgentWorker struct {
104104 stateMtx sync.Mutex
105105 state agentWorkerState
106106 currentJobID string
107+
108+ // disable the delay between pings, to speed up certain testing scenarios
109+ noWaitBetweenPingsForTesting bool
107110}
108111
109112type agentWorkerState string
@@ -294,6 +297,14 @@ func (a *AgentWorker) runPingLoop(ctx context.Context, idleMonitor *IdleMonitor)
294297 pingTicker := time .NewTicker (pingInterval )
295298 defer pingTicker .Stop ()
296299
300+ // testTriggerCh will normally block forever, and so will not affect the for/select loop.
301+ var testTriggerCh chan struct {}
302+ if a .noWaitBetweenPingsForTesting {
303+ // a closed channel will unblock the for/select instantly, for zero-delay ping loop testing.
304+ testTriggerCh = make (chan struct {})
305+ close (testTriggerCh )
306+ }
307+
297308 first := make (chan struct {}, 1 )
298309 first <- struct {}{}
299310
@@ -314,6 +325,8 @@ func (a *AgentWorker) runPingLoop(ctx context.Context, idleMonitor *IdleMonitor)
314325 for {
315326 setStat ("😴 Waiting until next ping interval tick" )
316327 select {
328+ case <- testTriggerCh :
329+ // instant receive from closed chan when noWaitBetweenPingsForTesting is true
317330 case <- first :
318331 // continue below
319332 case <- pingTicker .C :
@@ -329,6 +342,8 @@ func (a *AgentWorker) runPingLoop(ctx context.Context, idleMonitor *IdleMonitor)
329342 jitter := rand .N (pingInterval )
330343 setStat (fmt .Sprintf ("🫨 Jittering for %v" , jitter ))
331344 select {
345+ case <- testTriggerCh :
346+ // instant receive from closed chan when noWaitBetweenPingsForTesting is true
332347 case <- time .After (jitter ):
333348 // continue below
334349 case <- a .stop :
0 commit comments