Skip to content

Commit 8e23fe6

Browse files
committed
fix(test): put session_id after version check
1 parent 743ceb7 commit 8e23fe6

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

tests/std/connect_check_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@ func TestStdConnCheck(t *testing.T) {
4444
require.NoError(t, err)
4545

4646
dsns := map[clickhouse.Protocol]string{clickhouse.Native: fmt.Sprintf("clickhouse://%s:%d?username=%s&password=%s", env.Host, env.Port, env.Username, env.Password),
47-
clickhouse.HTTP: fmt.Sprintf("http://%s:%d?username=%s&password=%s&session_id=conn_test_session", env.Host, env.HttpPort, env.Username, env.Password)}
47+
clickhouse.HTTP: fmt.Sprintf("http://%s:%d?username=%s&password=%s", env.Host, env.HttpPort, env.Username, env.Password)}
4848
useSSL, err := strconv.ParseBool(clickhouse_tests.GetEnv("CLICKHOUSE_USE_SSL", "false"))
4949
require.NoError(t, err)
5050
if useSSL {
5151
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),
52-
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)}
52+
clickhouse.HTTP: fmt.Sprintf("https://%s:%d?username=%s&password=%s&secure=true", env.Host, env.HttpsPort, env.Username, env.Password)}
5353
}
5454
for name, dsn := range dsns {
5555
if name == clickhouse.Native && useSSL {
5656
//TODO: test fails over native and SSL - requires investigation
5757
continue
5858
}
5959
t.Run(fmt.Sprintf("%s Protocol", name), func(t *testing.T) {
60-
connect, err := GetConnectionFromDSN(dsn)
60+
connect, err := GetConnectionFromDSNWithSessionID(dsn, "conn_test_session")
6161
require.NoError(t, err)
6262
// We can only change the settings at the connection level.
6363
// If we have only one connection, we change the settings specifically for that connection.

tests/std/utils.go

+10
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ func GetDSNConnection(environment string, protocol clickhouse.Protocol, secure b
117117
}
118118

119119
func GetConnectionFromDSN(dsn string) (*sql.DB, error) {
120+
return GetConnectionFromDSNWithSessionID(dsn, "")
121+
}
122+
123+
func GetConnectionFromDSNWithSessionID(dsn string, sessionID string) (*sql.DB, error) {
120124
conn, err := sql.Open("clickhouse", dsn)
121125
if err != nil {
122126
return conn, err
@@ -134,6 +138,12 @@ func GetConnectionFromDSN(dsn string) (*sql.DB, error) {
134138
if strings.HasPrefix(dsn, "http") {
135139
dsn = fmt.Sprintf("%s&wait_end_of_query=1", dsn)
136140
}
141+
142+
// Optionally provide session ID after initial version check to prevent locking
143+
if len(sessionID) > 0 {
144+
dsn = fmt.Sprintf("%s&session_id=%s", dsn, sessionID)
145+
}
146+
137147
return sql.Open("clickhouse", dsn)
138148
}
139149

tests/std/uuid_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ func TestStdUUID(t *testing.T) {
3434
useSSL, err := strconv.ParseBool(clickhouse_tests.GetEnv("CLICKHOUSE_USE_SSL", "false"))
3535
require.NoError(t, err)
3636
dsns := map[string]string{"Native": fmt.Sprintf("clickhouse://%s:%d?username=%s&password=%s", env.Host, env.Port, env.Username, env.Password),
37-
"Http": fmt.Sprintf("http://%s:%d?username=%s&password=%s&session_id=uuid_test_session", env.Host, env.HttpPort, env.Username, env.Password)}
37+
"Http": fmt.Sprintf("http://%s:%d?username=%s&password=%s", env.Host, env.HttpPort, env.Username, env.Password)}
3838
if useSSL {
3939
dsns = map[string]string{"Native": fmt.Sprintf("clickhouse://%s:%d?username=%s&password=%s&secure=true", env.Host, env.SslPort, env.Username, env.Password),
40-
"Http": fmt.Sprintf("https://%s:%d?username=%s&password=%s&session_id=uuid_test_session&secure=true", env.Host, env.HttpsPort, env.Username, env.Password)}
40+
"Http": fmt.Sprintf("https://%s:%d?username=%s&password=%s&secure=true", env.Host, env.HttpsPort, env.Username, env.Password)}
4141
}
4242

4343
for name, dsn := range dsns {
4444
t.Run(fmt.Sprintf("%s Protocol", name), func(t *testing.T) {
45-
conn, err := GetConnectionFromDSN(dsn)
45+
conn, err := GetConnectionFromDSNWithSessionID(dsn, "uuid_test_session")
4646
require.NoError(t, err)
4747

4848
const ddl = `
@@ -86,14 +86,14 @@ func TestStdNullableUUID(t *testing.T) {
8686
useSSL, err := strconv.ParseBool(clickhouse_tests.GetEnv("CLICKHOUSE_USE_SSL", "false"))
8787
require.NoError(t, err)
8888
dsns := map[string]string{"Native": fmt.Sprintf("clickhouse://%s:%d?username=%s&password=%s", env.Host, env.Port, env.Username, env.Password),
89-
"Http": fmt.Sprintf("http://%s:%d?username=%s&password=%s&session_id=nullable_uuid_test_session", env.Host, env.HttpPort, env.Username, env.Password)}
89+
"Http": fmt.Sprintf("http://%s:%d?username=%s&password=%s", env.Host, env.HttpPort, env.Username, env.Password)}
9090
if useSSL {
9191
dsns = map[string]string{"Native": fmt.Sprintf("clickhouse://%s:%d?username=%s&password=%s&secure=true", env.Host, env.SslPort, env.Username, env.Password),
92-
"Http": fmt.Sprintf("https://%s:%d?username=%s&password=%s&session_id=nullable_uuid_test_session&secure=true", env.Host, env.HttpsPort, env.Username, env.Password)}
92+
"Http": fmt.Sprintf("https://%s:%d?username=%s&password=%s&secure=true", env.Host, env.HttpsPort, env.Username, env.Password)}
9393
}
9494
for name, dsn := range dsns {
9595
t.Run(fmt.Sprintf("%s Protocol", name), func(t *testing.T) {
96-
conn, err := GetConnectionFromDSN(dsn)
96+
conn, err := GetConnectionFromDSNWithSessionID(dsn, "nullable_uuid_test_session")
9797
require.NoError(t, err)
9898

9999
const ddl = `

0 commit comments

Comments
 (0)