Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce flakiness in ClickHouse tests #1902

Merged
merged 4 commits into from
Nov 13, 2023
Merged
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
36 changes: 23 additions & 13 deletions modules/clickhouse/clickhouse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down