Skip to content

Commit c408a25

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

File tree

6 files changed

+50
-28
lines changed

6 files changed

+50
-28
lines changed

internal/storage/integration/package_test.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ import (
1111
)
1212

1313
func TestMain(m *testing.M) {
14-
if os.Getenv("STORAGE") == "elasticsearch" || os.Getenv("STORAGE") == "opensearch" {
14+
switch os.Getenv("STORAGE") {
15+
case "elasticsearch":
1516
testutils.VerifyGoLeaksForES(m)
16-
} else {
17+
case "opensearch":
18+
testutils.VerifyGoLeaksForES(m)
19+
case "clickhouse":
20+
testutils.VerifyGoLeaksForCH(m)
21+
default:
1722
testutils.VerifyGoLeaks(m)
1823
}
1924
}

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)