From e2e812d17d8bbdb154009d3914b37c333bb4e2fc Mon Sep 17 00:00:00 2001 From: Kuba Kaflik Date: Wed, 27 Mar 2024 09:43:22 +0100 Subject: [PATCH] CI chores (#1258) * Avoid collisions in ClickHouse container name * chores * disable IPv6 in ClickHouse container * remove 23.12 --- .github/workflows/run-tests.yml | 4 +- examples/std/main_test.go | 9 ++-- examples/std/session.go | 85 --------------------------------- tests/resources/custom.xml | 2 +- tests/utils.go | 12 ++++- 5 files changed, 17 insertions(+), 95 deletions(-) delete mode 100644 examples/std/session.go diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 57cdfd2427..a35e324bbe 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -20,9 +20,9 @@ jobs: - "1.22" - "1.21" clickhouse: # https://github.com/ClickHouse/ClickHouse/blob/master/SECURITY.md#scope-and-supported-versions - - "latest" # 24.2 + - "latest" # 24.3 + - "24.2" - "24.1" - - "23.12" - "23.8" - "23.3" steps: diff --git a/examples/std/main_test.go b/examples/std/main_test.go index 8e080ae9b4..b4450c35d1 100644 --- a/examples/std/main_test.go +++ b/examples/std/main_test.go @@ -20,13 +20,14 @@ package std import ( "context" "fmt" - clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests" - "github.com/stretchr/testify/require" "math/rand" "os" "strconv" "testing" "time" + + clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests" + "github.com/stretchr/testify/require" ) func TestMain(m *testing.M) { @@ -132,10 +133,6 @@ func TestStdProgress(t *testing.T) { require.NoError(t, ProgressProfileLogs()) } -func TestStdSession(t *testing.T) { - require.NoError(t, Sessions()) -} - func TestStdDynamicScan(t *testing.T) { require.NoError(t, DynamicScan()) } diff --git a/examples/std/session.go b/examples/std/session.go deleted file mode 100644 index b848d51865..0000000000 --- a/examples/std/session.go +++ /dev/null @@ -1,85 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package std - -import ( - "fmt" - "github.com/ClickHouse/clickhouse-go/v2" - "github.com/google/uuid" -) - -func Sessions() error { - env, err := GetStdTestEnvironment() - if err != nil { - return err - } - conn := clickhouse.OpenDB(&clickhouse.Options{ - Addr: []string{fmt.Sprintf("%s:%d", env.Host, env.HttpPort)}, - Auth: clickhouse.Auth{ - Database: env.Database, - Username: env.Username, - Password: env.Password, - }, - Protocol: clickhouse.HTTP, - Settings: clickhouse.Settings{ - "session_id": uuid.NewString(), - }, - }) - if _, err := conn.Exec(`DROP TABLE IF EXISTS example`); err != nil { - return err - } - _, err = conn.Exec(` - CREATE TEMPORARY TABLE IF NOT EXISTS example ( - Col1 UInt8 - ) - `) - if err != nil { - return err - } - scope, err := conn.Begin() - if err != nil { - return err - } - batch, err := scope.Prepare("INSERT INTO example") - if err != nil { - return err - } - for i := 0; i < 10; i++ { - _, err := batch.Exec( - uint8(i), - ) - if err != nil { - return err - } - } - rows, err := conn.Query("SELECT * FROM example") - if err != nil { - return err - } - var ( - col1 uint8 - ) - for rows.Next() { - if err := rows.Scan(&col1); err != nil { - return err - } - fmt.Printf("row: col1=%d\n", col1) - } - - return nil -} diff --git a/tests/resources/custom.xml b/tests/resources/custom.xml index 3b485d8e4a..7545cb89d3 100644 --- a/tests/resources/custom.xml +++ b/tests/resources/custom.xml @@ -1,6 +1,6 @@ - :: + 0.0.0.0 1 8443 9440 diff --git a/tests/utils.go b/tests/utils.go index ed707f6fb2..e4826be1b2 100644 --- a/tests/utils.go +++ b/tests/utils.go @@ -18,9 +18,12 @@ package tests import ( + "bytes" "context" + "crypto/md5" "crypto/tls" "database/sql" + "encoding/binary" "encoding/json" "errors" "fmt" @@ -148,9 +151,16 @@ func CreateClickHouseTestEnvironment(testSet string) (ClickHouseTestEnvironment, Soft: 262144, }, } + + buf := new(bytes.Buffer) + if err := binary.Write(buf, binary.LittleEndian, time.Now().UnixNano()); err != nil { + return ClickHouseTestEnvironment{}, err + } + containerName := fmt.Sprintf("clickhouse-go-%x", md5.Sum(buf.Bytes())) + req := testcontainers.ContainerRequest{ Image: fmt.Sprintf("clickhouse/clickhouse-server:%s", GetClickHouseTestVersion()), - Name: fmt.Sprintf("clickhouse-go-%s-%d", strings.ToLower(testSet), time.Now().UnixNano()), + Name: containerName, ExposedPorts: []string{"9000/tcp", "8123/tcp", "9440/tcp", "8443/tcp"}, WaitingFor: wait.ForAll( wait.ForLog("Ready for connections").WithStartupTimeout(time.Second*time.Duration(120)),