Skip to content

Commit

Permalink
[chore][receiver/scraperhelper] Enable goleak check (#9226)
Browse files Browse the repository at this point in the history
**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
Add `goleak` to detect leaks in tests. Leaking goroutines were detected
that were caused by a dependency that we can ignore
(`go.opencensus.io/stats/view.(*worker).start`), a `Shutdown` call was
also added that was missing.

**Link to tracking Issue:** <Issue number if applicable>
#9165 

**Testing:** <Describe what testing was performed and which tests were
added.>
Added check is passing as well as existing tests.
  • Loading branch information
crobert-1 committed Jan 5, 2024
1 parent df1ff47 commit 5cdf27c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions receiver/scraperhelper/package_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package scraperhelper

import (
"testing"

"go.uber.org/goleak"
)

// The IgnoreTopFunction call prevents catching the leak generated by opencensus
// defaultWorker.Start which at this time is part of the package's init call.
// See https://github.com/open-telemetry/opentelemetry-collector/issues/9165#issuecomment-1874836336 for more context.
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m, goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"))
}
1 change: 1 addition & 0 deletions receiver/scraperhelper/scrapercontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ func TestSingleScrapePerInterval(t *testing.T) {
require.NoError(t, err)

require.NoError(t, receiver.Start(context.Background(), componenttest.NewNopHost()))
defer func() { require.NoError(t, receiver.Shutdown(context.Background())) }()

tickerCh <- time.Now()

Expand Down

0 comments on commit 5cdf27c

Please sign in to comment.