From ebac0ca73bbf251b070bb6df4d8005015841f901 Mon Sep 17 00:00:00 2001 From: Feng Ruohang Date: Wed, 2 Sep 2026 20:04:57 +0800 Subject: [PATCH] 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 Claude-Session: https://claude.ai/code/session_01PvgysXDmhPBBimCReYtA8q Signed-off-by: Feng Ruohang --- cmd/dynamic-timeouts_test.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cmd/dynamic-timeouts_test.go b/cmd/dynamic-timeouts_test.go index b353b983b..dd0e306c2 100644 --- a/cmd/dynamic-timeouts_test.go +++ b/cmd/dynamic-timeouts_test.go @@ -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() }) }