Skip to content

Commit

Permalink
Fix goroutine leaks in some packages (#5038)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?
- part of #5006 

## Description of the changes
- fix goroutine leaks in some package and add goleak check

## How was this change tested?
- go test

---------

Signed-off-by: Harshvir Potpose <hpotpose62@gmail.com>
  • Loading branch information
akagami-harsh committed Dec 25, 2023
1 parent 7d1cc9f commit 16985d4
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/agent/app/reporter/client_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func testClientMetricsWithParams(params ClientMetricsReporterParams, fn func(tr
r1 := testutils.NewInMemoryReporter()
zapCore, logs := observer.New(zap.DebugLevel)
mb := metricstest.NewFactory(time.Hour)
defer mb.Stop()

params.Reporter = r1
params.Logger = zap.New(zapCore)
Expand Down
1 change: 1 addition & 0 deletions cmd/agent/app/reporter/connect_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

func TestConnectMetrics(t *testing.T) {
mf := metricstest.NewFactory(time.Hour)
defer mf.Stop()
cm := NewConnectMetrics(mf)

getGauge := func() map[string]int64 {
Expand Down
1 change: 1 addition & 0 deletions cmd/agent/app/reporter/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func TestMetricsReporter(t *testing.T) {

for _, test := range tests {
metricsFactory := metricstest.NewFactory(time.Microsecond)
defer metricsFactory.Stop()
r := WrapWithMetrics(test.rep, metricsFactory)
test.action(r)
metricsFactory.AssertCounterMetrics(t, test.expectedCounters...)
Expand Down
25 changes: 25 additions & 0 deletions cmd/agent/app/reporter/package_test.go
Original file line number Diff line number Diff line change
@@ -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 reporter

import (
"testing"

"go.uber.org/goleak"
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}
7 changes: 7 additions & 0 deletions pkg/httpmetrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/internal/metrics/prometheus"
Expand All @@ -37,6 +38,7 @@ func TestNewMetricsHandler(t *testing.T) {
})

mb := metricstest.NewFactory(time.Hour)
defer mb.Stop()
handler := Wrap(dummyHandlerFunc, mb, zap.NewNop())

req, err := http.NewRequest(http.MethodGet, "/subdir/qwerty", nil)
Expand All @@ -56,6 +58,7 @@ func TestNewMetricsHandler(t *testing.T) {

func TestMaxEntries(t *testing.T) {
mf := metricstest.NewFactory(time.Hour)
defer mf.Stop()
r := newRequestDurations(mf, zap.NewNop())
r.maxEntries = 1
r.record(recordedRequest{
Expand Down Expand Up @@ -85,3 +88,7 @@ func TestIllegalPrometheusLabel(t *testing.T) {
require.NoError(t, err)
handler.ServeHTTP(httptest.NewRecorder(), req)
}

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}
5 changes: 5 additions & 0 deletions pkg/recoveryhandler/zap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"

"github.com/jaegertracing/jaeger/pkg/testutils"
)
Expand All @@ -45,3 +46,7 @@ func TestNewRecoveryHandler(t *testing.T) {
"msg": "Unexpected error!",
}, log.JSONLine(0))
}

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}

0 comments on commit 16985d4

Please sign in to comment.