From c38ec5cab617bd7a83b82d66be69c62019da6987 Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Thu, 4 Apr 2024 17:53:39 -0700 Subject: [PATCH] [chore][receiver/snowflake] Enable goleak check (#32182) **Description:** This enables the `goleak` check for the Snowflake receiver to help ensure no goroutines are being leaked. This is a test only change, a couple shutdown/close calls were missing. **Link to tracking Issue:** #30438 **Testing:** All existing tests are passing, as well as added `goleak` check. --- receiver/snowflakereceiver/client_test.go | 5 +++-- receiver/snowflakereceiver/package_test.go | 15 +++++++++++++++ receiver/snowflakereceiver/scraper_test.go | 1 + 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 receiver/snowflakereceiver/package_test.go diff --git a/receiver/snowflakereceiver/client_test.go b/receiver/snowflakereceiver/client_test.go index 743c9b817eee..30d43c724941 100644 --- a/receiver/snowflakereceiver/client_test.go +++ b/receiver/snowflakereceiver/client_test.go @@ -18,7 +18,7 @@ import ( ) func TestDefaultClientCreation(t *testing.T) { - _, err := newDefaultClient(componenttest.NewNopTelemetrySettings(), Config{ + c, err := newDefaultClient(componenttest.NewNopTelemetrySettings(), Config{ Username: "testuser", Password: "testPassword", Account: "testAccount", @@ -27,7 +27,8 @@ func TestDefaultClientCreation(t *testing.T) { Database: "testDatabase", Role: "testRole", }) - assert.Equal(t, nil, err) + assert.NoError(t, err) + assert.NoError(t, c.client.Close()) } // test query wrapper diff --git a/receiver/snowflakereceiver/package_test.go b/receiver/snowflakereceiver/package_test.go new file mode 100644 index 000000000000..354238689a68 --- /dev/null +++ b/receiver/snowflakereceiver/package_test.go @@ -0,0 +1,15 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package snowflakereceiver + +import ( + "testing" + + "go.uber.org/goleak" +) + +// Regarding the godbus/dbus ignore: see https://github.com/99designs/keyring/issues/103 +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, goleak.IgnoreAnyFunction("github.com/godbus/dbus.(*Conn).inWorker")) +} diff --git a/receiver/snowflakereceiver/scraper_test.go b/receiver/snowflakereceiver/scraper_test.go index f07ec6e36ed9..5d7f4b62c523 100644 --- a/receiver/snowflakereceiver/scraper_test.go +++ b/receiver/snowflakereceiver/scraper_test.go @@ -72,6 +72,7 @@ func TestStart(t *testing.T) { scraper := newSnowflakeMetricsScraper(receivertest.NewNopCreateSettings(), cfg) err := scraper.start(context.Background(), componenttest.NewNopHost()) require.NoError(t, err, "Problem starting scraper") + require.NoError(t, scraper.shutdown(context.Background())) } // wrapper type for convenience