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 2 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
39 changes: 26 additions & 13 deletions modules/clickhouse/clickhouse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"context"
"path/filepath"
"testing"
"time"

ch "github.com/ClickHouse/clickhouse-go/v2"
"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
"github.com/stretchr/testify/assert"

"github.com/testcontainers/testcontainers-go"
)

Expand Down Expand Up @@ -218,22 +218,35 @@ 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 (
maxRetry = 5
delay = 100 * time.Millisecond
err error
rows []Test
)

err = conn.Exec(context.Background(), "INSERT INTO test_table (id) VALUES (1);")
if err != nil {
return nil, err
}
for i := 0; i < maxRetry; i++ {
mdelapenya marked this conversation as resolved.
Show resolved Hide resolved
time.Sleep(time.Duration(i) * delay)

rows, err := getAllRows(conn)
if err != nil {
return nil, err
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 {
continue
}

err = conn.Exec(context.Background(), "INSERT INTO test_table (id) VALUES (1);")
if err != nil {
continue
}

rows, err = getAllRows(conn)
if err != nil {
continue
}

return rows, err
}

return rows, nil
return rows, err
}

func getAllRows(conn driver.Conn) ([]Test, error) {
Expand Down