From a83456484e061ee6b390195e357a4e5cf7950164 Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Wed, 6 Mar 2024 15:26:15 -0800 Subject: [PATCH] [chore] add goleak tests for splunkhecreceiver (#31619) Related to #30438 --- receiver/splunkhecreceiver/go.mod | 1 + receiver/splunkhecreceiver/package_test.go | 14 ++++++++++++++ receiver/splunkhecreceiver/receiver_test.go | 15 +++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 receiver/splunkhecreceiver/package_test.go diff --git a/receiver/splunkhecreceiver/go.mod b/receiver/splunkhecreceiver/go.mod index 2454c66fb8cdf..20c0eb3fa8133 100644 --- a/receiver/splunkhecreceiver/go.mod +++ b/receiver/splunkhecreceiver/go.mod @@ -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 ) diff --git a/receiver/splunkhecreceiver/package_test.go b/receiver/splunkhecreceiver/package_test.go new file mode 100644 index 0000000000000..a1a634e3d239b --- /dev/null +++ b/receiver/splunkhecreceiver/package_test.go @@ -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")) +} diff --git a/receiver/splunkhecreceiver/receiver_test.go b/receiver/splunkhecreceiver/receiver_test.go index ec7ab4c2ed963..b87c26305619a 100644 --- a/receiver/splunkhecreceiver/receiver_test.go +++ b/receiver/splunkhecreceiver/receiver_test.go @@ -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) @@ -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) @@ -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) @@ -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) @@ -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)