diff --git a/relay/healthcheck/receiver.go b/relay/healthcheck/receiver.go index 299adba15..9819f4651 100644 --- a/relay/healthcheck/receiver.go +++ b/relay/healthcheck/receiver.go @@ -11,13 +11,13 @@ import ( var heartbeatTimeout = healthCheckInterval + 10*time.Second var mux sync.Mutex -func getHealthCheckInterval() time.Duration { +func getHeartBeatTimeout() time.Duration { mux.Lock() defer mux.Unlock() return heartbeatTimeout } -func setHealthCheckInterval(interval time.Duration) { +func setHeartBeatTimeout(interval time.Duration) { mux.Lock() defer mux.Unlock() heartbeatTimeout = interval @@ -68,7 +68,7 @@ func (r *Receiver) Stop() { } func (r *Receiver) waitForHealthcheck() { - ticker := time.NewTicker(getHealthCheckInterval()) + ticker := time.NewTicker(getHeartBeatTimeout()) defer ticker.Stop() defer r.ctxCancel() defer close(r.OnTimeout) diff --git a/relay/healthcheck/receiver_test.go b/relay/healthcheck/receiver_test.go index 60f165af0..8d5e67cdf 100644 --- a/relay/healthcheck/receiver_test.go +++ b/relay/healthcheck/receiver_test.go @@ -11,7 +11,7 @@ import ( ) func TestNewReceiver(t *testing.T) { - setHealthCheckInterval(5 * time.Second) + setHeartBeatTimeout(5 * time.Second) r := NewReceiver(log.WithContext(context.Background())) select { @@ -23,7 +23,7 @@ func TestNewReceiver(t *testing.T) { } func TestNewReceiverNotReceive(t *testing.T) { - setHealthCheckInterval(1 * time.Second) + setHeartBeatTimeout(1 * time.Second) r := NewReceiver(log.WithContext(context.Background())) select { @@ -34,7 +34,7 @@ func TestNewReceiverNotReceive(t *testing.T) { } func TestNewReceiverAck(t *testing.T) { - setHealthCheckInterval(2 * time.Second) + setHeartBeatTimeout(2 * time.Second) r := NewReceiver(log.WithContext(context.Background())) r.Heartbeat() @@ -60,12 +60,12 @@ func TestReceiverHealthCheckAttemptThreshold(t *testing.T) { for _, tc := range testsCases { t.Run(tc.name, func(t *testing.T) { originalInterval := healthCheckInterval - originalTimeout := getHealthCheckInterval() + originalTimeout := getHeartBeatTimeout() healthCheckInterval = 1 * time.Second - setHealthCheckInterval(originalTimeout + 500*time.Millisecond) + setHeartBeatTimeout(healthCheckInterval + 500*time.Millisecond) defer func() { healthCheckInterval = originalInterval - setHealthCheckInterval(originalTimeout) + setHeartBeatTimeout(originalTimeout) }() //nolint:tenv os.Setenv(defaultAttemptThresholdEnv, fmt.Sprintf("%d", tc.threshold))