Skip to content

Commit

Permalink
[chore][exporter/exporterhelper] Enable goleak test
Browse files Browse the repository at this point in the history
This enables goleak to run on tests within exporter/exporterhelper.
A known leak needs to be ignored, and we need to explicitly call
shutdown on the queue to make sure no routines are still running
after the test is complete.
  • Loading branch information
crobert-1 committed Jan 4, 2024
1 parent 3673059 commit cb5d261
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions exporter/exporterhelper/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 exporterhelper

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 exporter/exporterhelper/queue_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ func TestQueuedRetryPersistentEnabled_NoDataLossOnShutdown(t *testing.T) {

// wait for the item to be consumed from the queue
replacedReq.checkNumRequests(t, 1)
require.NoError(t, be.Shutdown(context.Background()))
}

func TestQueueSenderNoStartShutdown(t *testing.T) {
Expand Down

0 comments on commit cb5d261

Please sign in to comment.