From cb5d261504ae8a70b565cc9df3586126dbf53e57 Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Wed, 3 Jan 2024 14:54:42 -0800 Subject: [PATCH] [chore][exporter/exporterhelper] Enable goleak test 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. --- exporter/exporterhelper/package_test.go | 17 +++++++++++++++++ exporter/exporterhelper/queue_sender_test.go | 1 + 2 files changed, 18 insertions(+) create mode 100644 exporter/exporterhelper/package_test.go diff --git a/exporter/exporterhelper/package_test.go b/exporter/exporterhelper/package_test.go new file mode 100644 index 000000000000..0980e46319f8 --- /dev/null +++ b/exporter/exporterhelper/package_test.go @@ -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")) +} diff --git a/exporter/exporterhelper/queue_sender_test.go b/exporter/exporterhelper/queue_sender_test.go index fe0633a605d5..0af3c37b3540 100644 --- a/exporter/exporterhelper/queue_sender_test.go +++ b/exporter/exporterhelper/queue_sender_test.go @@ -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) {