diff --git a/clickhouse.go b/clickhouse.go index c0d981b203..b0a09587df 100644 --- a/clickhouse.go +++ b/clickhouse.go @@ -269,6 +269,7 @@ func (ch *clickhouse) dial(ctx context.Context) (conn nativeTransport, err error } func DefaultDialStrategy(ctx context.Context, connID int, opt *Options, dial Dial) (r DialResult, err error) { + random := rand.Int() for i := range opt.Addr { var num int switch opt.ConnOpenStrategy { @@ -277,7 +278,6 @@ func DefaultDialStrategy(ctx context.Context, connID int, opt *Options, dial Dia case ConnOpenRoundRobin: num = (connID + i) % len(opt.Addr) case ConnOpenRandom: - random := rand.Int() num = (random + i) % len(opt.Addr) } diff --git a/clickhouse_std.go b/clickhouse_std.go index 38f4e09b4b..43354eb682 100644 --- a/clickhouse_std.go +++ b/clickhouse_std.go @@ -88,13 +88,14 @@ func (o *stdConnOpener) Connect(ctx context.Context) (_ driver.Conn, err error) for i := range o.opt.Addr { var num int + random := rand.Int() + switch o.opt.ConnOpenStrategy { case ConnOpenInOrder: num = i case ConnOpenRoundRobin: num = (connID + i) % len(o.opt.Addr) case ConnOpenRandom: - random := rand.Int() num = (random + i) % len(o.opt.Addr) } if conn, err = dialFunc(ctx, o.opt.Addr[num], connID, o.opt); err == nil { diff --git a/examples/clickhouse_api/main_test.go b/examples/clickhouse_api/main_test.go index 9eb0cde48f..a276732f88 100644 --- a/examples/clickhouse_api/main_test.go +++ b/examples/clickhouse_api/main_test.go @@ -28,9 +28,6 @@ import ( ) func TestMain(m *testing.M) { - ResetRandSeed() - fmt.Printf("using random seed %d for %s tests\n", randSeed, TestSet) - useDocker, err := strconv.ParseBool(clickhouse_tests.GetEnv("CLICKHOUSE_USE_DOCKER", "true")) if err != nil { panic(err) @@ -160,7 +157,7 @@ func TestMultiHostConnect(t *testing.T) { require.NoError(t, MultiHostRoundRobinVersion()) }) t.Run("Random", func(t *testing.T) { - t.Skip("Go 1.25 math/random changes") + // t.Skip("Go 1.25 math/random changes") require.NoError(t, MultiHostRandomVersion()) }) } diff --git a/examples/clickhouse_api/multi_host.go b/examples/clickhouse_api/multi_host.go index 033b248227..ec191078d7 100644 --- a/examples/clickhouse_api/multi_host.go +++ b/examples/clickhouse_api/multi_host.go @@ -19,7 +19,6 @@ package clickhouse_api import ( "fmt" - "math/rand" "github.com/ClickHouse/clickhouse-go/v2" ) @@ -34,8 +33,6 @@ func MultiHostRoundRobinVersion() error { } func MultiHostRandomVersion() error { - rand.Seed(85206178671753424) - defer ResetRandSeed() connOpenStrategy := clickhouse.ConnOpenRandom return multiHostVersion(&connOpenStrategy) } diff --git a/examples/clickhouse_api/utils.go b/examples/clickhouse_api/utils.go index e442c48147..d9f4ce62ed 100644 --- a/examples/clickhouse_api/utils.go +++ b/examples/clickhouse_api/utils.go @@ -22,8 +22,6 @@ import ( "github.com/ClickHouse/clickhouse-go/v2" "github.com/ClickHouse/clickhouse-go/v2/lib/driver" clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests" - "math/rand" - "time" ) const TestSet string = "examples_clickhouse_api" @@ -43,9 +41,3 @@ func GetNativeConnectionWithOptions(settings clickhouse.Settings, tlsConfig *tls func CheckMinServerVersion(conn driver.Conn, major, minor, patch uint64) bool { return clickhouse_tests.CheckMinServerServerVersion(conn, major, minor, patch) } - -var randSeed = time.Now().UnixNano() - -func ResetRandSeed() { - rand.Seed(randSeed) -} diff --git a/examples/std/main_test.go b/examples/std/main_test.go index a0029f330a..90d71e81f6 100644 --- a/examples/std/main_test.go +++ b/examples/std/main_test.go @@ -20,20 +20,15 @@ package std import ( "context" "fmt" - "math/rand" "os" "strconv" "testing" - "time" clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests" "github.com/stretchr/testify/require" ) func TestMain(m *testing.M) { - seed := time.Now().UnixNano() - fmt.Printf("using random seed %d for %s tests\n", seed, TestSet) - rand.Seed(seed) useDocker, err := strconv.ParseBool(clickhouse_tests.GetEnv("CLICKHOUSE_USE_DOCKER", "true")) if err != nil { panic(err) diff --git a/tests/conn_test.go b/tests/conn_test.go index d722155025..cfae464ddf 100644 --- a/tests/conn_test.go +++ b/tests/conn_test.go @@ -76,9 +76,6 @@ func TestConnFailoverRoundRobin(t *testing.T) { } func TestConnFailoverRandom(t *testing.T) { - t.Skip("Go 1.25 math/random changes") - //rand.Seed(85206178671753423) - //defer ResetRandSeed() testConnFailover(t, clickhouse.ConnOpenRandom) } diff --git a/tests/std/conn_test.go b/tests/std/conn_test.go index 6f44fa1188..457f4383da 100644 --- a/tests/std/conn_test.go +++ b/tests/std/conn_test.go @@ -59,9 +59,7 @@ func TestStdConnFailoverRoundRobin(t *testing.T) { } func TestStdConnFailoverRandom(t *testing.T) { - t.Skip("Go 1.25 math/random changes") - //rand.Seed(85206178671753428) - //defer clickhouse_tests.ResetRandSeed() + // t.Skip("Go 1.25 math/random changes") testStdConnFailover(t, "random") } diff --git a/tests/utils.go b/tests/utils.go index 08bcb4bcd0..aa8612f934 100644 --- a/tests/utils.go +++ b/tests/utils.go @@ -52,7 +52,6 @@ import ( var testUUID = uuid.NewString()[0:12] var testTimestamp = time.Now().UnixMilli() -var randSeed = time.Now().UnixNano() const defaultClickHouseVersion = "latest" @@ -970,14 +969,7 @@ func OptionsToDSN(o *clickhouse.Options) string { return u.String() } -func ResetRandSeed() { - rand.Seed(randSeed) -} - func Runtime(m *testing.M, ts string) (exitCode int) { - ResetRandSeed() - fmt.Printf("using random seed %d for %s tests\n", randSeed, ts) - useDocker, err := strconv.ParseBool(GetEnv("CLICKHOUSE_USE_DOCKER", "true")) if err != nil { panic(err)