forked from mtusi2026/mtusi2026lab5
lab5 na4
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user