Skip to content

Commit 044859b

Browse files
committed
jobs: fix TestJitterCalculation failed
This test will sometimes fail due to a randomly picking a value that rounds to 1/2. The frequency of this is a bit higher than one would expect because the rounding behavior depends on the width of the duration, not the width of a float64. The test was adjusted to retry if the jittered value equals the input. Release note: none Fixes: #128381 Fixes: #157113
1 parent 33ebee8 commit 044859b

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

pkg/jobs/registry_test.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"context"
1010
gosql "database/sql"
1111
"fmt"
12+
"math/rand"
1213
"strconv"
1314
"strings"
1415
"sync/atomic"
@@ -710,13 +711,17 @@ func TestJitterCalculation(t *testing.T) {
710711
},
711712
} {
712713
t.Run(test.name, func(t *testing.T) {
713-
interval := jitter(test.input)
714+
interval := test.input
715+
testutils.SucceedsSoon(t, func() error {
716+
interval = jitter(test.input)
717+
if interval == test.input {
718+
return errors.New("jitter returned same value as input")
719+
}
720+
return nil
721+
})
714722
rangeMin, rangeMax := outputRange(test.input)
715723
require.GreaterOrEqual(t, rangeMax, interval)
716724
require.LessOrEqual(t, rangeMin, interval)
717-
if test.input != 0 {
718-
require.NotEqual(t, test.input, interval)
719-
}
720725
})
721726
}
722727
}

0 commit comments

Comments
 (0)