cloud-game/pkg/worker/worker_test.go
2026-07-03 11:36:49 +03:00

30 lines
484 B
Go

package worker
import (
"testing"
"testing/synctest"
"time"
)
func TestBackoff(t *testing.T) {
synctest.Test(t, func(t *testing.T) {
n := 10 * time.Minute
d := n
// 10min -> 20 -> 40 -> 60 -> 60 ...
for i := range 5 {
backoff(&d, 1*time.Hour)
if i > 2 {
if d != 1*time.Hour {
t.Errorf("cap: got %v, want 1h", d)
}
} else {
x := n * 2 * time.Duration(i+1)
if d != x {
t.Errorf("next wait: got %v, want %v", d, x)
}
}
}
})
}