Skip to content

Commit 19bc811

Browse files
committed
add more test
Signed-off-by: zzzk1 <[email protected]>
1 parent 9570553 commit 19bc811

File tree

7 files changed

+46
-27
lines changed

7 files changed

+46
-27
lines changed

internal/storage/integration/clickhouse_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package integration
55

66
import (
7+
"github.com/jaegertracing/jaeger/pkg/testutils"
78
"testing"
89

910
"github.com/stretchr/testify/assert"
@@ -13,7 +14,6 @@ import (
1314

1415
"github.com/jaegertracing/jaeger/internal/storage/v2/clickhouse"
1516
"github.com/jaegertracing/jaeger/pkg/clickhouse/config"
16-
"github.com/jaegertracing/jaeger/pkg/testutils"
1717
)
1818

1919
type ClickhouseIntegrationTestSuite struct {

internal/storage/integration/package_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
func TestMain(m *testing.M) {
1414
if os.Getenv("STORAGE") == "elasticsearch" || os.Getenv("STORAGE") == "opensearch" {
1515
testutils.VerifyGoLeaksForES(m)
16+
} else if os.Getenv("STORAGE") == "clickhouse" {
17+
testutils.VerifyGoLeaksForCH(m)
1618
} else {
1719
testutils.VerifyGoLeaks(m)
1820
}

internal/storage/v2/clickhouse/factory_test.go

+1-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package clickhouse
66
import (
77
"testing"
88

9-
"github.com/ClickHouse/ch-go/cht"
109
"github.com/stretchr/testify/assert"
1110
"github.com/stretchr/testify/require"
1211
"go.uber.org/zap"
@@ -24,21 +23,14 @@ func TestClickHouseFactoryWithConfig(t *testing.T) {
2423
},
2524
ConnectionPoolConfig: config.ConnectionPoolConfig{},
2625
}
27-
// provide a tcp server for testing.
28-
cht.New(t,
29-
cht.WithLog(zap.NewNop()),
30-
)
26+
3127
f, err := NewFactoryWithConfig(&cfg, zap.NewNop())
3228
require.NoError(t, err)
3329
defer f.Close()
3430
}
3531

3632
func TestCreateTraceWriter(t *testing.T) {
3733
cfg := config.DefaultConfiguration()
38-
// provide a tcp server for testing.
39-
cht.New(t,
40-
cht.WithLog(zap.NewNop()),
41-
)
4234

4335
f, err := NewFactoryWithConfig(&cfg, zap.NewNop())
4436
require.NoError(t, err)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) 2024 The Jaeger Authors.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package clickhouse
5+
6+
import (
7+
"testing"
8+
9+
"github.com/jaegertracing/jaeger/pkg/testutils"
10+
)
11+
12+
func TestMain(m *testing.M) {
13+
testutils.VerifyGoLeaksForCH(m)
14+
}

pkg/clickhouse/config/config_test.go

+2-17
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package config
66
import (
77
"testing"
88

9-
"github.com/ClickHouse/ch-go/cht"
109
"github.com/stretchr/testify/assert"
1110
"github.com/stretchr/testify/require"
1211
"go.uber.org/zap"
@@ -23,11 +22,8 @@ func TestNewClientWithDefaults(t *testing.T) {
2322
cfg := DefaultConfiguration()
2423
logger := zap.NewNop()
2524

26-
cht.New(t,
27-
cht.WithLog(logger),
28-
)
29-
3025
client, err := cfg.NewClient(logger)
26+
3127
require.NoError(t, err)
3228
assert.NotEmpty(t, client)
3329
defer client.Close()
@@ -36,11 +32,7 @@ func TestNewClientWithDefaults(t *testing.T) {
3632
func TestNewPool(t *testing.T) {
3733
cfg := DefaultConfiguration()
3834
logger := zap.NewNop()
39-
conn, err := cfg.newConn()
40-
41-
cht.New(t,
42-
cht.WithLog(logger),
43-
)
35+
conn, err := cfg.newPool(logger)
4436

4537
require.NoError(t, err)
4638
assert.NotEmpty(t, conn)
@@ -52,19 +44,12 @@ func TestNewPoolFail(t *testing.T) {
5244
logger := zap.NewNop()
5345
pool, err := cfg.newPool(logger)
5446

55-
cht.New(t,
56-
cht.WithLog(logger),
57-
)
58-
5947
require.Error(t, err)
6048
assert.Nil(t, pool)
6149
}
6250

6351
func TestNewConnection(t *testing.T) {
6452
cfg := DefaultConfiguration()
65-
logger := zap.NewNop()
66-
67-
cht.New(t, cht.WithLog(logger))
6853

6954
conn, err := cfg.newConn()
7055
require.NoError(t, err)

pkg/clickhouse/config/package_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) 2024 The Jaeger Authors.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package config
5+
6+
import (
7+
"testing"
8+
9+
"github.com/jaegertracing/jaeger/pkg/testutils"
10+
)
11+
12+
func TestMain(m *testing.M) {
13+
testutils.VerifyGoLeaksForCH(m)
14+
}

pkg/testutils/leakcheck.go

+12
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ func ignoreHttpTransportReadLoopLeak() goleak.Option {
5555
return goleak.IgnoreTopFunction("net/http.(*persistConn).readLoop")
5656
}
5757

58+
func ignoreBackgroundHealthCheck() goleak.Option {
59+
return goleak.IgnoreTopFunction("github.com/ClickHouse/ch-go/chpool.(*Pool).backgroundHealthCheck")
60+
}
61+
62+
func ignoreStartAutoCloseIdleConnections() goleak.Option {
63+
return goleak.IgnoreTopFunction("github.com/ClickHouse/clickhouse-go/v2.(*clickhouse).startAutoCloseIdleConnections")
64+
}
65+
5866
// VerifyGoLeaks verifies that unit tests do not leak any goroutines.
5967
// It should be called in TestMain.
6068
func VerifyGoLeaks(m *testing.M) {
@@ -82,3 +90,7 @@ func VerifyGoLeaksOnceForES(t *testing.T) {
8290
func VerifyGoLeaksForES(m *testing.M) {
8391
goleak.VerifyTestMain(m, ignoreHttpTransportWriteLoopLeak(), ignoreHttpTransportPollRuntimeLeak(), ignoreHttpTransportReadLoopLeak())
8492
}
93+
94+
func VerifyGoLeaksForCH(m *testing.M) {
95+
goleak.VerifyTestMain(m, ignoreHttpTransportWriteLoopLeak(), ignoreHttpTransportPollRuntimeLeak(), ignoreBackgroundHealthCheck(), ignoreStartAutoCloseIdleConnections())
96+
}

0 commit comments

Comments
 (0)