Skip to content

Commit 4751283

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 4751283

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

pkg/jobs/registry_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -710,13 +710,17 @@ func TestJitterCalculation(t *testing.T) {
710710
},
711711
} {
712712
t.Run(test.name, func(t *testing.T) {
713-
interval := jitter(test.input)
713+
interval := test.input
714+
testutils.SucceedsSoon(t, func() error {
715+
interval = jitter(test.input)
716+
if interval == test.input && test.input != 0 {
717+
return errors.New("jitter returned same value as input")
718+
}
719+
return nil
720+
})
714721
rangeMin, rangeMax := outputRange(test.input)
715722
require.GreaterOrEqual(t, rangeMax, interval)
716723
require.LessOrEqual(t, rangeMin, interval)
717-
if test.input != 0 {
718-
require.NotEqual(t, test.input, interval)
719-
}
720724
})
721725
}
722726
}

0 commit comments

Comments
 (0)