From 19bc8118eaef2f71956e6b376126b3d824f80145 Mon Sep 17 00:00:00 2001 From: zzzk1 Date: Sat, 15 Feb 2025 20:39:43 +0800 Subject: [PATCH] add more test Signed-off-by: zzzk1 --- .../storage/integration/clickhouse_test.go | 2 +- internal/storage/integration/package_test.go | 2 ++ .../storage/v2/clickhouse/factory_test.go | 10 +--------- .../storage/v2/clickhouse/package_test.go | 14 ++++++++++++++ pkg/clickhouse/config/config_test.go | 19 ++----------------- pkg/clickhouse/config/package_test.go | 14 ++++++++++++++ pkg/testutils/leakcheck.go | 12 ++++++++++++ 7 files changed, 46 insertions(+), 27 deletions(-) create mode 100644 internal/storage/v2/clickhouse/package_test.go create mode 100644 pkg/clickhouse/config/package_test.go diff --git a/internal/storage/integration/clickhouse_test.go b/internal/storage/integration/clickhouse_test.go index a6da571b07b..4effe47c4d1 100644 --- a/internal/storage/integration/clickhouse_test.go +++ b/internal/storage/integration/clickhouse_test.go @@ -4,6 +4,7 @@ package integration import ( + "github.com/jaegertracing/jaeger/pkg/testutils" "testing" "github.com/stretchr/testify/assert" @@ -13,7 +14,6 @@ import ( "github.com/jaegertracing/jaeger/internal/storage/v2/clickhouse" "github.com/jaegertracing/jaeger/pkg/clickhouse/config" - "github.com/jaegertracing/jaeger/pkg/testutils" ) type ClickhouseIntegrationTestSuite struct { diff --git a/internal/storage/integration/package_test.go b/internal/storage/integration/package_test.go index bf7665a5329..b441348c749 100644 --- a/internal/storage/integration/package_test.go +++ b/internal/storage/integration/package_test.go @@ -13,6 +13,8 @@ import ( func TestMain(m *testing.M) { if os.Getenv("STORAGE") == "elasticsearch" || os.Getenv("STORAGE") == "opensearch" { testutils.VerifyGoLeaksForES(m) + } else if os.Getenv("STORAGE") == "clickhouse" { + testutils.VerifyGoLeaksForCH(m) } else { testutils.VerifyGoLeaks(m) } diff --git a/internal/storage/v2/clickhouse/factory_test.go b/internal/storage/v2/clickhouse/factory_test.go index 02f7bfd7ec2..a5f5801af56 100644 --- a/internal/storage/v2/clickhouse/factory_test.go +++ b/internal/storage/v2/clickhouse/factory_test.go @@ -6,7 +6,6 @@ package clickhouse import ( "testing" - "github.com/ClickHouse/ch-go/cht" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/zap" @@ -24,10 +23,7 @@ func TestClickHouseFactoryWithConfig(t *testing.T) { }, ConnectionPoolConfig: config.ConnectionPoolConfig{}, } - // provide a tcp server for testing. - cht.New(t, - cht.WithLog(zap.NewNop()), - ) + f, err := NewFactoryWithConfig(&cfg, zap.NewNop()) require.NoError(t, err) defer f.Close() @@ -35,10 +31,6 @@ func TestClickHouseFactoryWithConfig(t *testing.T) { func TestCreateTraceWriter(t *testing.T) { cfg := config.DefaultConfiguration() - // provide a tcp server for testing. - cht.New(t, - cht.WithLog(zap.NewNop()), - ) f, err := NewFactoryWithConfig(&cfg, zap.NewNop()) require.NoError(t, err) diff --git a/internal/storage/v2/clickhouse/package_test.go b/internal/storage/v2/clickhouse/package_test.go new file mode 100644 index 00000000000..02eed04abce --- /dev/null +++ b/internal/storage/v2/clickhouse/package_test.go @@ -0,0 +1,14 @@ +// Copyright (c) 2024 The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 + +package clickhouse + +import ( + "testing" + + "github.com/jaegertracing/jaeger/pkg/testutils" +) + +func TestMain(m *testing.M) { + testutils.VerifyGoLeaksForCH(m) +} diff --git a/pkg/clickhouse/config/config_test.go b/pkg/clickhouse/config/config_test.go index 2054411b2d3..ccab1118a09 100644 --- a/pkg/clickhouse/config/config_test.go +++ b/pkg/clickhouse/config/config_test.go @@ -6,7 +6,6 @@ package config import ( "testing" - "github.com/ClickHouse/ch-go/cht" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/zap" @@ -23,11 +22,8 @@ func TestNewClientWithDefaults(t *testing.T) { cfg := DefaultConfiguration() logger := zap.NewNop() - cht.New(t, - cht.WithLog(logger), - ) - client, err := cfg.NewClient(logger) + require.NoError(t, err) assert.NotEmpty(t, client) defer client.Close() @@ -36,11 +32,7 @@ func TestNewClientWithDefaults(t *testing.T) { func TestNewPool(t *testing.T) { cfg := DefaultConfiguration() logger := zap.NewNop() - conn, err := cfg.newConn() - - cht.New(t, - cht.WithLog(logger), - ) + conn, err := cfg.newPool(logger) require.NoError(t, err) assert.NotEmpty(t, conn) @@ -52,19 +44,12 @@ func TestNewPoolFail(t *testing.T) { logger := zap.NewNop() pool, err := cfg.newPool(logger) - cht.New(t, - cht.WithLog(logger), - ) - require.Error(t, err) assert.Nil(t, pool) } func TestNewConnection(t *testing.T) { cfg := DefaultConfiguration() - logger := zap.NewNop() - - cht.New(t, cht.WithLog(logger)) conn, err := cfg.newConn() require.NoError(t, err) diff --git a/pkg/clickhouse/config/package_test.go b/pkg/clickhouse/config/package_test.go new file mode 100644 index 00000000000..652eb5e8603 --- /dev/null +++ b/pkg/clickhouse/config/package_test.go @@ -0,0 +1,14 @@ +// Copyright (c) 2024 The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 + +package config + +import ( + "testing" + + "github.com/jaegertracing/jaeger/pkg/testutils" +) + +func TestMain(m *testing.M) { + testutils.VerifyGoLeaksForCH(m) +} diff --git a/pkg/testutils/leakcheck.go b/pkg/testutils/leakcheck.go index 7f2db13cf01..5f180401ebc 100644 --- a/pkg/testutils/leakcheck.go +++ b/pkg/testutils/leakcheck.go @@ -55,6 +55,14 @@ func ignoreHttpTransportReadLoopLeak() goleak.Option { return goleak.IgnoreTopFunction("net/http.(*persistConn).readLoop") } +func ignoreBackgroundHealthCheck() goleak.Option { + return goleak.IgnoreTopFunction("github.com/ClickHouse/ch-go/chpool.(*Pool).backgroundHealthCheck") +} + +func ignoreStartAutoCloseIdleConnections() goleak.Option { + return goleak.IgnoreTopFunction("github.com/ClickHouse/clickhouse-go/v2.(*clickhouse).startAutoCloseIdleConnections") +} + // VerifyGoLeaks verifies that unit tests do not leak any goroutines. // It should be called in TestMain. func VerifyGoLeaks(m *testing.M) { @@ -82,3 +90,7 @@ func VerifyGoLeaksOnceForES(t *testing.T) { func VerifyGoLeaksForES(m *testing.M) { goleak.VerifyTestMain(m, ignoreHttpTransportWriteLoopLeak(), ignoreHttpTransportPollRuntimeLeak(), ignoreHttpTransportReadLoopLeak()) } + +func VerifyGoLeaksForCH(m *testing.M) { + goleak.VerifyTestMain(m, ignoreHttpTransportWriteLoopLeak(), ignoreHttpTransportPollRuntimeLeak(), ignoreBackgroundHealthCheck(), ignoreStartAutoCloseIdleConnections()) +}