Skip to content

Commit

Permalink
[chore][receiver/azureeventhub] Enable goleak check (#32364)
Browse files Browse the repository at this point in the history
**Description:** 
This enables `goleak` checks for the Azure Event Hub receiver to help
ensure no goroutines are being leaked. This is a test only change, some
goroutines were being detected as leaks simply because of the
context.Background lifecycle. Using a cancel shows everything gets
shutdown properly.

**Link to tracking Issue:** #30438 

**Testing:** 
All existing tests are passing, as well as added `goleak` check.
  • Loading branch information
crobert-1 authored Apr 13, 2024
1 parent c07d1e6 commit b142064
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
12 changes: 8 additions & 4 deletions receiver/azureeventhubreceiver/eventhubhandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ func (m *mockDataConsumer) consume(ctx context.Context, event *eventhub.Event) e
}

func TestEventhubHandler_Start(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

config := createDefaultConfig()
config.(*Config).Connection = "Endpoint=sb://namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=superSecret1234=;EntityPath=hubName"
Expand All @@ -95,14 +97,16 @@ func TestEventhubHandler_Start(t *testing.T) {
}
ehHandler.hub = &mockHubWrapper{}

err := ehHandler.run(context.Background(), componenttest.NewNopHost())
err := ehHandler.run(ctx, componenttest.NewNopHost())
assert.NoError(t, err)

err = ehHandler.close(context.Background())
err = ehHandler.close(ctx)
assert.NoError(t, err)
}

func TestEventhubHandler_newMessageHandler(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

config := createDefaultConfig()
config.(*Config).Connection = "Endpoint=sb://namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=superSecret1234=;EntityPath=hubName"
Expand All @@ -127,11 +131,11 @@ func TestEventhubHandler_newMessageHandler(t *testing.T) {
}
ehHandler.hub = &mockHubWrapper{}

err = ehHandler.run(context.Background(), componenttest.NewNopHost())
err = ehHandler.run(ctx, componenttest.NewNopHost())
assert.NoError(t, err)

now := time.Now()
err = ehHandler.newMessageHandler(context.Background(), &eventhub.Event{
err = ehHandler.newMessageHandler(ctx, &eventhub.Event{
Data: []byte("hello"),
PartitionKey: nil,
Properties: map[string]any{"foo": "bar"},
Expand Down
1 change: 1 addition & 0 deletions receiver/azureeventhubreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (
go.opentelemetry.io/collector/semconv v0.98.1-0.20240412014414-62f589864e3d
go.opentelemetry.io/otel/metric v1.25.0
go.opentelemetry.io/otel/trace v1.25.0
go.uber.org/goleak v1.3.0
go.uber.org/zap v1.27.0
)

Expand Down
14 changes: 14 additions & 0 deletions receiver/azureeventhubreceiver/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 azureeventhubreceiver

import (
"testing"

"go.uber.org/goleak"
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}

0 comments on commit b142064

Please sign in to comment.