mirror of
https://github.com/pgsty/minio.git
synced 2026-09-05 18:16:16 +03:00
test: give the dynamic timeout tests a private random source
TestDynamicTimeoutAdjustExponential and TestDynamicTimeoutAdjustNormal seeded the global generator and then drew from it while other tests in the package may use the same generator, so the sample was not the one the seed promised and the exponential case failed once in a full race run. A private source makes both tests deterministic. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PvgysXDmhPBBimCReYtA8q Signed-off-by: Feng Ruohang <rh@vonng.com>
This commit is contained in:
@@ -180,12 +180,14 @@ func testDynamicTimeoutAdjust(t *testing.T, timeout *dynamicTimeout, f func() fl
|
||||
func TestDynamicTimeoutAdjustExponential(t *testing.T) {
|
||||
timeout := newDynamicTimeout(time.Minute, time.Second)
|
||||
|
||||
rand.Seed(0)
|
||||
// A private source keeps the sample independent of other tests that use
|
||||
// the global generator concurrently.
|
||||
rng := rand.New(rand.NewSource(0))
|
||||
|
||||
initial := timeout.Timeout()
|
||||
|
||||
for range 10 {
|
||||
testDynamicTimeoutAdjust(t, timeout, rand.ExpFloat64)
|
||||
testDynamicTimeoutAdjust(t, timeout, rng.ExpFloat64)
|
||||
}
|
||||
|
||||
adjusted := timeout.Timeout()
|
||||
@@ -197,13 +199,13 @@ func TestDynamicTimeoutAdjustExponential(t *testing.T) {
|
||||
func TestDynamicTimeoutAdjustNormalized(t *testing.T) {
|
||||
timeout := newDynamicTimeout(time.Minute, time.Second)
|
||||
|
||||
rand.Seed(0)
|
||||
rng := rand.New(rand.NewSource(0))
|
||||
|
||||
initial := timeout.Timeout()
|
||||
|
||||
for range 10 {
|
||||
testDynamicTimeoutAdjust(t, timeout, func() float64 {
|
||||
return 1.0 + rand.NormFloat64()
|
||||
return 1.0 + rng.NormFloat64()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user