Skip to content

Commit

Permalink
add more test
Browse files Browse the repository at this point in the history
Signed-off-by: zzzk1 <[email protected]>
  • Loading branch information
zzzk1 committed Feb 15, 2025
1 parent 9570553 commit 19bc811
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 27 deletions.
2 changes: 1 addition & 1 deletion internal/storage/integration/clickhouse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package integration

import (
"github.com/jaegertracing/jaeger/pkg/testutils"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions internal/storage/integration/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
10 changes: 1 addition & 9 deletions internal/storage/v2/clickhouse/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -24,21 +23,14 @@ 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()
}

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)
Expand Down
14 changes: 14 additions & 0 deletions internal/storage/v2/clickhouse/package_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
19 changes: 2 additions & 17 deletions pkg/clickhouse/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()
Expand All @@ -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)
Expand All @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions pkg/clickhouse/config/package_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
12 changes: 12 additions & 0 deletions pkg/testutils/leakcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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())
}

0 comments on commit 19bc811

Please sign in to comment.