diff --git a/modules/clickhouse/clickhouse_test.go b/modules/clickhouse/clickhouse_test.go index bd505689dc..ea2670388b 100644 --- a/modules/clickhouse/clickhouse_test.go +++ b/modules/clickhouse/clickhouse_test.go @@ -7,6 +7,7 @@ import ( ch "github.com/ClickHouse/clickhouse-go/v2" "github.com/ClickHouse/clickhouse-go/v2/lib/driver" + "github.com/cenkalti/backoff/v4" "github.com/stretchr/testify/assert" "github.com/testcontainers/testcontainers-go" @@ -218,22 +219,31 @@ func TestClickHouseWithConfigFile(t *testing.T) { } func performCRUD(conn driver.Conn) ([]Test, error) { - err := conn.Exec(context.Background(), "create table if not exists test_table (id UInt64) engine = MergeTree PRIMARY KEY (id) ORDER BY (id) SETTINGS index_granularity = 8192;") - if err != nil { - return nil, err - } + var ( + err error + rows []Test + ) - err = conn.Exec(context.Background(), "INSERT INTO test_table (id) VALUES (1);") - if err != nil { - return nil, err - } + err = backoff.Retry(func() error { + err = conn.Exec(context.Background(), "create table if not exists test_table (id UInt64) engine = MergeTree PRIMARY KEY (id) ORDER BY (id) SETTINGS index_granularity = 8192;") + if err != nil { + return err + } - rows, err := getAllRows(conn) - if err != nil { - return nil, err - } + err = conn.Exec(context.Background(), "INSERT INTO test_table (id) VALUES (1);") + if err != nil { + return err + } + + rows, err = getAllRows(conn) + if err != nil { + return err + } + + return nil + }, backoff.NewExponentialBackOff()) - return rows, nil + return rows, err } func getAllRows(conn driver.Conn) ([]Test, error) {