Skip to content

Commit

Permalink
[chore] add goleak tests for splunkhecreceiver (#31619)
Browse files Browse the repository at this point in the history
Related to #30438
  • Loading branch information
atoulme authored and DougManton committed Mar 13, 2024
1 parent bf63a87 commit a834564
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions receiver/splunkhecreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
go.opentelemetry.io/collector/semconv v0.96.1-0.20240306115632-b2693620eff6
go.opentelemetry.io/otel/metric v1.24.0
go.opentelemetry.io/otel/trace v1.24.0
go.uber.org/goleak v1.3.0
go.uber.org/zap v1.27.0
)

Expand Down
14 changes: 14 additions & 0 deletions receiver/splunkhecreceiver/package_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package splunkhecreceiver

import (
"testing"

"go.uber.org/goleak"
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m, goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"))
}
15 changes: 15 additions & 0 deletions receiver/splunkhecreceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,9 @@ func Test_splunkhecReceiver_TLS(t *testing.T) {

require.NoError(t, r.Start(context.Background(), componenttest.NewNopHost()), "should not have failed to start log reception")
require.NoError(t, r.Start(context.Background(), componenttest.NewNopHost()), "should not fail to start log on second Start call")
defer func() {
require.NoError(t, r.Shutdown(context.Background()))
}()

// If there are errors reported through ReportStatus this will retrieve it.
<-time.After(500 * time.Millisecond)
Expand Down Expand Up @@ -627,6 +630,9 @@ func Test_splunkhecReceiver_AccessTokenPassthrough(t *testing.T) {
if tt.metric {
exporter, err := factory.CreateMetricsExporter(context.Background(), exportertest.NewNopCreateSettings(), exporterConfig)
assert.NoError(t, exporter.Start(context.Background(), nil))
defer func() {
require.NoError(t, exporter.Shutdown(context.Background()))
}()
assert.NoError(t, err)
rcv, err := newMetricsReceiver(receivertest.NewNopCreateSettings(), *config, exporter)
assert.NoError(t, err)
Expand All @@ -640,6 +646,9 @@ func Test_splunkhecReceiver_AccessTokenPassthrough(t *testing.T) {
} else {
exporter, err := factory.CreateLogsExporter(context.Background(), exportertest.NewNopCreateSettings(), exporterConfig)
assert.NoError(t, exporter.Start(context.Background(), nil))
defer func() {
require.NoError(t, exporter.Shutdown(context.Background()))
}()
assert.NoError(t, err)
rcv, err := newLogsReceiver(receivertest.NewNopCreateSettings(), *config, exporter)
assert.NoError(t, err)
Expand Down Expand Up @@ -707,6 +716,9 @@ func Test_Logs_splunkhecReceiver_IndexSourceTypePassthrough(t *testing.T) {
exporter, err := factory.CreateLogsExporter(context.Background(), exportertest.NewNopCreateSettings(), exporterConfig)
assert.NoError(t, exporter.Start(context.Background(), nil))
assert.NoError(t, err)
defer func() {
require.NoError(t, exporter.Shutdown(context.Background()))
}()
rcv, err := newLogsReceiver(receivertest.NewNopCreateSettings(), *cfg, exporter)
assert.NoError(t, err)

Expand Down Expand Up @@ -804,6 +816,9 @@ func Test_Metrics_splunkhecReceiver_IndexSourceTypePassthrough(t *testing.T) {

exporter, err := factory.CreateMetricsExporter(context.Background(), exportertest.NewNopCreateSettings(), exporterConfig)
assert.NoError(t, exporter.Start(context.Background(), nil))
defer func() {
require.NoError(t, exporter.Shutdown(context.Background()))
}()
assert.NoError(t, err)
rcv, err := newMetricsReceiver(receivertest.NewNopCreateSettings(), *cfg, exporter)
assert.NoError(t, err)
Expand Down

0 comments on commit a834564

Please sign in to comment.