diff --git a/cmd/ingester/app/consumer/package_test.go b/cmd/ingester/app/consumer/package_test.go new file mode 100644 index 00000000000..287cb02e5b4 --- /dev/null +++ b/cmd/ingester/app/consumer/package_test.go @@ -0,0 +1,25 @@ +// Copyright (c) 2023 The Jaeger Authors. +// +// Licensed 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 consumer + +import ( + "testing" + + "go.uber.org/goleak" +) + +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} diff --git a/cmd/ingester/app/consumer/processor_factory_test.go b/cmd/ingester/app/consumer/processor_factory_test.go index 5ea0fe8e7b8..f64721e8e76 100644 --- a/cmd/ingester/app/consumer/processor_factory_test.go +++ b/cmd/ingester/app/consumer/processor_factory_test.go @@ -55,6 +55,7 @@ func Test_new(t *testing.T) { } processor := pf.new(topic, partition, offset) + defer processor.Close() msg := &kmocks.Message{} msg.On("Offset").Return(offset + 1) processor.Process(msg) diff --git a/cmd/internal/env/command_test.go b/cmd/internal/env/command_test.go index 20baed3f423..4169b70eeae 100644 --- a/cmd/internal/env/command_test.go +++ b/cmd/internal/env/command_test.go @@ -20,6 +20,9 @@ import ( "testing" "github.com/stretchr/testify/assert" + "go.uber.org/goleak" + + "github.com/jaegertracing/jaeger/pkg/testutils" ) func TestCommand(t *testing.T) { @@ -30,3 +33,7 @@ func TestCommand(t *testing.T) { assert.True(t, strings.Contains(buf.String(), "METRICS_BACKEND")) assert.True(t, strings.Contains(buf.String(), "SPAN_STORAGE")) } + +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutils.IgnoreGlogFlushDaemonLeak()) +} diff --git a/pkg/testutils/leakcheck.go b/pkg/testutils/leakcheck.go new file mode 100644 index 00000000000..b5e25503382 --- /dev/null +++ b/pkg/testutils/leakcheck.go @@ -0,0 +1,27 @@ +// Copyright (c) 2023 The Jaeger Authors. +// +// Licensed 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 testutils + +import ( + "go.uber.org/goleak" +) + +// IgnoreGlogFlushDaemonLeak returns a goleak.Option that ignores the flushDaemon function +// from the glog package that can cause false positives in leak detection. +// This is necessary because glog starts a goroutine in the background that may not +// be stopped when the test finishes, leading to a detected but expected leak. +func IgnoreGlogFlushDaemonLeak() goleak.Option { + return goleak.IgnoreTopFunction("github.com/golang/glog.(*fileSink).flushDaemon") +} diff --git a/pkg/testutils/leakcheck_test.go b/pkg/testutils/leakcheck_test.go new file mode 100644 index 00000000000..4fa06e9f8cd --- /dev/null +++ b/pkg/testutils/leakcheck_test.go @@ -0,0 +1,26 @@ +// Copyright (c) 2023 The Jaeger Authors. +// +// Licensed 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 testutils + +import ( + "testing" +) + +func TestIgnoreGlogFlushDaemonLeak(t *testing.T) { + opt := IgnoreGlogFlushDaemonLeak() + if opt == nil { + t.Errorf("IgnoreGlogFlushDaemonLeak() returned nil, want non-nil goleak.Option") + } +} diff --git a/plugin/storage/badger/dependencystore/package_test.go b/plugin/storage/badger/dependencystore/package_test.go new file mode 100644 index 00000000000..a2d168f1f48 --- /dev/null +++ b/plugin/storage/badger/dependencystore/package_test.go @@ -0,0 +1,27 @@ +// Copyright (c) 2023 The Jaeger Authors. +// +// Licensed 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 dependencystore + +import ( + "testing" + + "go.uber.org/goleak" + + "github.com/jaegertracing/jaeger/pkg/testutils" +) + +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutils.IgnoreGlogFlushDaemonLeak()) +} diff --git a/plugin/storage/badger/package_test.go b/plugin/storage/badger/package_test.go new file mode 100644 index 00000000000..6fc584128b3 --- /dev/null +++ b/plugin/storage/badger/package_test.go @@ -0,0 +1,27 @@ +// Copyright (c) 2023 The Jaeger Authors. +// +// Licensed 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 badger + +import ( + "testing" + + "go.uber.org/goleak" + + "github.com/jaegertracing/jaeger/pkg/testutils" +) + +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutils.IgnoreGlogFlushDaemonLeak()) +} diff --git a/plugin/storage/badger/samplingstore/storage_test.go b/plugin/storage/badger/samplingstore/storage_test.go index 1e0bedc1ca0..8296f966c92 100644 --- a/plugin/storage/badger/samplingstore/storage_test.go +++ b/plugin/storage/badger/samplingstore/storage_test.go @@ -22,8 +22,10 @@ import ( "github.com/dgraph-io/badger/v3" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" samplemodel "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/model" + "github.com/jaegertracing/jaeger/pkg/testutils" ) func newTestSamplingStore(db *badger.DB) *SamplingStore { @@ -139,3 +141,7 @@ func runWithBadger(t *testing.T, test func(t *testing.T, store *SamplingStore)) ss := newTestSamplingStore(store) test(t, ss) } + +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutils.IgnoreGlogFlushDaemonLeak()) +} diff --git a/plugin/storage/badger/spanstore/package_test.go b/plugin/storage/badger/spanstore/package_test.go new file mode 100644 index 00000000000..a601b5f157b --- /dev/null +++ b/plugin/storage/badger/spanstore/package_test.go @@ -0,0 +1,27 @@ +// Copyright (c) 2023 The Jaeger Authors. +// +// Licensed 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 spanstore + +import ( + "testing" + + "go.uber.org/goleak" + + "github.com/jaegertracing/jaeger/pkg/testutils" +) + +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutils.IgnoreGlogFlushDaemonLeak()) +} diff --git a/plugin/storage/factory_test.go b/plugin/storage/factory_test.go index c82b9f03dca..c5220e0c3e1 100644 --- a/plugin/storage/factory_test.go +++ b/plugin/storage/factory_test.go @@ -411,7 +411,9 @@ func TestPublishOpts(t *testing.T) { require.NoError(t, err) baseMetrics := metricstest.NewFactory(time.Second) + baseMetrics.Stop() forkFactory := metricstest.NewFactory(time.Second) + forkFactory.Stop() metricsFactory := fork.New("internal", forkFactory, baseMetrics) f.metricsFactory = metricsFactory diff --git a/plugin/storage/package_test.go b/plugin/storage/package_test.go new file mode 100644 index 00000000000..7627d753b67 --- /dev/null +++ b/plugin/storage/package_test.go @@ -0,0 +1,27 @@ +// Copyright (c) 2023 The Jaeger Authors. +// +// Licensed 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 storage + +import ( + "testing" + + "go.uber.org/goleak" + + "github.com/jaegertracing/jaeger/pkg/testutils" +) + +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutils.IgnoreGlogFlushDaemonLeak()) +}