Skip to content

Commit a8c47b3

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 2ec926e commit a8c47b3

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

pkg/jobs/registry_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,13 +1226,21 @@ func TestJitterCalculation(t *testing.T) {
12261226
},
12271227
} {
12281228
t.Run(test.name, func(t *testing.T) {
1229-
interval := jitter(test.input)
1229+
interval := test.input
1230+
testutils.SucceedsSoon(t, func() error {
1231+
interval = jitter(test.input)
1232+
// This check will sometimes fail due to a randomly picking a value
1233+
// that rounds to 1/2. The frequency of this is a bit higher than one
1234+
// would expect because the rounding behavior depends on the width of
1235+
// the duration, not the width of a float64.
1236+
if interval == test.input && test.input != 0 {
1237+
return errors.New("jitter returned same value as input")
1238+
}
1239+
return nil
1240+
})
12301241
rangeMin, rangeMax := outputRange(test.input)
12311242
require.GreaterOrEqual(t, rangeMax, interval)
12321243
require.LessOrEqual(t, rangeMin, interval)
1233-
if test.input != 0 {
1234-
require.NotEqual(t, test.input, interval)
1235-
}
12361244
})
12371245
}
12381246
}

0 commit comments

Comments
 (0)