Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}

Expand Down
3 changes: 2 additions & 1 deletion clickhouse_std.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 1 addition & 4 deletions examples/clickhouse_api/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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())
})
}
Expand Down
3 changes: 0 additions & 3 deletions examples/clickhouse_api/multi_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package clickhouse_api

import (
"fmt"
"math/rand"

"github.com/ClickHouse/clickhouse-go/v2"
)
Expand All @@ -34,8 +33,6 @@ func MultiHostRoundRobinVersion() error {
}

func MultiHostRandomVersion() error {
rand.Seed(85206178671753424)
defer ResetRandSeed()
connOpenStrategy := clickhouse.ConnOpenRandom
return multiHostVersion(&connOpenStrategy)
}
Expand Down
8 changes: 0 additions & 8 deletions examples/clickhouse_api/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
}
5 changes: 0 additions & 5 deletions examples/std/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions tests/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 1 addition & 3 deletions tests/std/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
8 changes: 0 additions & 8 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import (

var testUUID = uuid.NewString()[0:12]
var testTimestamp = time.Now().UnixMilli()
var randSeed = time.Now().UnixNano()

const defaultClickHouseVersion = "latest"

Expand Down Expand Up @@ -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)
Expand Down
Loading