Skip to content

Commit

Permalink
[chore][receiver/podman] Enable goleak check
Browse files Browse the repository at this point in the history
  • Loading branch information
crobert-1 committed Apr 5, 2024
1 parent 4e413a7 commit ebcea03
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions receiver/podmanreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
go.opentelemetry.io/collector/semconv v0.97.1-0.20240404121116-4f1a8936d26b
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/multierr v1.11.0
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.21.0
Expand Down
14 changes: 14 additions & 0 deletions receiver/podmanreceiver/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 podmanreceiver

import (
"testing"

"go.uber.org/goleak"
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}
9 changes: 7 additions & 2 deletions receiver/podmanreceiver/podman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ func TestEventLoopHandlesError(t *testing.T) {
cli := newContainerScraper(client, zap.New(observed), config)
assert.NotNil(t, cli)

go cli.containerEventLoop(context.Background())
ctx, cancel := context.WithCancel(context.Background())
go cli.containerEventLoop(ctx)
defer cancel()

assert.Eventually(t, func() bool {
for _, l := range logs.All() {
Expand Down Expand Up @@ -176,7 +178,10 @@ func TestEventLoopHandles(t *testing.T) {

assert.Equal(t, 0, len(cli.containers))

go cli.containerEventLoop(context.Background())
ctx, cancel := context.WithCancel(context.Background())
go cli.containerEventLoop(ctx)
defer cancel()

eventChan <- event{ID: "c1", Status: "start"}

assert.Eventually(t, func() bool {
Expand Down
9 changes: 6 additions & 3 deletions receiver/podmanreceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ func TestScraperLoop(t *testing.T) {
client := make(mockClient)
consumer := make(mockConsumer)

r, err := newMetricsReceiver(context.Background(), receivertest.NewNopCreateSettings(), cfg, consumer, client.factory)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

r, err := newMetricsReceiver(ctx, receivertest.NewNopCreateSettings(), cfg, consumer, client.factory)
require.NoError(t, err)
assert.NotNil(t, r)

Expand All @@ -70,12 +73,12 @@ func TestScraperLoop(t *testing.T) {
}
}()

assert.NoError(t, r.Start(context.Background(), componenttest.NewNopHost()))
assert.NoError(t, r.Start(ctx, componenttest.NewNopHost()))

md := <-consumer
assert.Equal(t, md.ResourceMetrics().Len(), 1)

assert.NoError(t, r.Shutdown(context.Background()))
assert.NoError(t, r.Shutdown(ctx))
}

type mockClient chan containerStatsReport
Expand Down

0 comments on commit ebcea03

Please sign in to comment.