1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
package workloadapi
import (
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestLinearBackoff(t *testing.T) {
testUntilMax := func(t *testing.T, b *linearBackoff) {
for i := 1; i < 30; i++ {
require.Equal(t, time.Duration(i)*time.Second, b.Next())
}
require.Equal(t, 30*time.Second, b.Next())
require.Equal(t, 30*time.Second, b.Next())
require.Equal(t, 30*time.Second, b.Next())
}
t.Run("test max", func(t *testing.T) {
t.Parallel()
b := newLinearBackoff()
testUntilMax(t, b)
})
t.Run("test reset", func(t *testing.T) {
t.Parallel()
b := newLinearBackoff()
testUntilMax(t, b)
b.Reset()
testUntilMax(t, b)
})
}
|