Skip to content

Commit

Permalink
fix: close duplicate connection in DSN helper func
Browse files Browse the repository at this point in the history
  • Loading branch information
SpencerTorres committed Feb 27, 2025
1 parent 4411a95 commit 62b3c99
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions tests/std/connect_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ func TestStdConnCheck(t *testing.T) {
require.NoError(t, err)

dsns := map[clickhouse.Protocol]string{clickhouse.Native: fmt.Sprintf("clickhouse://%s:%d?username=%s&password=%s", env.Host, env.Port, env.Username, env.Password),
clickhouse.HTTP: fmt.Sprintf("http://%s:%d?username=%s&password=%s&session_id=test_session", env.Host, env.HttpPort, env.Username, env.Password)}
clickhouse.HTTP: fmt.Sprintf("http://%s:%d?username=%s&password=%s&session_id=conn_test_session", env.Host, env.HttpPort, env.Username, env.Password)}
useSSL, err := strconv.ParseBool(clickhouse_tests.GetEnv("CLICKHOUSE_USE_SSL", "false"))
require.NoError(t, err)
if useSSL {
dsns = map[clickhouse.Protocol]string{clickhouse.Native: fmt.Sprintf("clickhouse://%s:%d?username=%s&password=%s&secure=true", env.Host, env.SslPort, env.Username, env.Password),
clickhouse.HTTP: fmt.Sprintf("https://%s:%d?username=%s&password=%s&session_id=test_session&secure=true", env.Host, env.HttpsPort, env.Username, env.Password)}
clickhouse.HTTP: fmt.Sprintf("https://%s:%d?username=%s&password=%s&session_id=conn_test_session&secure=true", env.Host, env.HttpsPort, env.Username, env.Password)}
}
for name, dsn := range dsns {
if name == clickhouse.Native && useSSL {
Expand Down
5 changes: 5 additions & 0 deletions tests/std/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ func GetConnectionFromDSN(dsn string) (*sql.DB, error) {
if CheckMinServerVersion(conn, 22, 8, 0) {
dsn = fmt.Sprintf("%s&database_replicated_enforce_synchronous_settings=1", dsn)
}
err = conn.Close()
if err != nil {
return conn, err
}

insertQuorum := clickhouse_tests.GetEnv("CLICKHOUSE_QUORUM_INSERT", "1")
dsn = fmt.Sprintf("%s&insert_quorum=%s&insert_quorum_parallel=0&select_sequential_consistency=1", dsn, insertQuorum)
if strings.HasPrefix(dsn, "http") {
Expand Down
2 changes: 0 additions & 2 deletions tests/std/uuid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func TestStdUUID(t *testing.T) {
t.Run(fmt.Sprintf("%s Protocol", name), func(t *testing.T) {
conn, err := GetConnectionFromDSN(dsn)
require.NoError(t, err)
conn.SetMaxOpenConns(1)

const ddl = `
CREATE TEMPORARY TABLE test_uuid (
Expand Down Expand Up @@ -96,7 +95,6 @@ func TestStdNullableUUID(t *testing.T) {
t.Run(fmt.Sprintf("%s Protocol", name), func(t *testing.T) {
conn, err := GetConnectionFromDSN(dsn)
require.NoError(t, err)
conn.SetMaxOpenConns(1)

const ddl = `
CREATE TEMPORARY TABLE test_uuid (
Expand Down

0 comments on commit 62b3c99

Please sign in to comment.