rename and use getHeartBeatTimeout and setHeartBeatTimeout

This commit is contained in:
Maycon Santos
2025-07-20 21:57:24 +02:00
parent 62deb64f5f
commit 4e737a482b
2 changed files with 9 additions and 9 deletions

View File

@@ -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)

View File

@@ -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))