Skip to content

Commit

Permalink
[chore][internal/docker] Enable goleak check (#32046)
Browse files Browse the repository at this point in the history
**Description:** 
This enables `goleak` to help ensure no goroutines are being leaked in
the `internal/docker` package. This is a test only change, an existing
test was leaking a goroutine because it wasn't cancelling a context
properly.

**Link to tracking Issue:** #30438 

**Testing:**
Existing tests are passing, as well as added `goleak` check.
  • Loading branch information
crobert-1 authored Mar 30, 2024
1 parent 6be6423 commit 144f640
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion internal/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ func TestEventLoopHandlesError(t *testing.T) {
assert.NotNil(t, cli)
assert.NoError(t, err)

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
1 change: 1 addition & 0 deletions internal/docker/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/docker/docker v25.0.5+incompatible
github.com/gobwas/glob v0.2.3
github.com/stretchr/testify v1.9.0
go.uber.org/goleak v1.3.0
go.uber.org/zap v1.27.0
)

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

import (
"testing"

"go.uber.org/goleak"
)

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

0 comments on commit 144f640

Please sign in to comment.