Files
mtusi2026lab6/internal/jobs/repository_test.go
T
2026-11-19 13:39:53 +03:00

30 lines
559 B
Go

package jobs
import (
"testing"
"time"
)
func TestRetryBackoffJitterAndCap(t *testing.T) {
for attempt := 1; attempt <= 12; attempt++ {
base := time.Second
for i := 1; i < attempt && base < 60*time.Second; i++ {
base *= 2
}
if base > 60*time.Second {
base = 60 * time.Second
}
values := map[time.Duration]bool{}
for i := 0; i < 50; i++ {
d := RetryDelay(attempt)
if d < base/2 || d > base {
t.Fatalf("attempt=%d delay=%s", attempt, d)
}
values[d] = true
}
if len(values) < 2 {
t.Fatal("jitter absent")
}
}
}