Skip to content

Commit

Permalink
[chore][config/configgrpc] Enable goleak
Browse files Browse the repository at this point in the history
Enables goleak to run on the configgrpc package. Requires
ignoring the opencensus-go leak.
  • Loading branch information
crobert-1 committed Jan 4, 2024
1 parent 3673059 commit 81f9bd9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion config/configgrpc/configgrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ func TestHttpReception(t *testing.T) {
assert.NoError(t, errResp)
assert.NotNil(t, resp)
}
assert.NoError(t, grpcClientConn.Close())
cancelFunc()
s.Stop()
})
Expand Down Expand Up @@ -685,6 +686,7 @@ func TestReceiveOnUnixDomainSocket(t *testing.T) {
resp, errResp := c.Export(ctx, ptraceotlp.NewExportRequest(), grpc.WaitForReady(true))
assert.NoError(t, errResp)
assert.NotNil(t, resp)
assert.NoError(t, grpcClientConn.Close())
cancelFunc()
srv.Stop()
}
Expand Down Expand Up @@ -848,6 +850,7 @@ func TestClientInfoInterceptors(t *testing.T) {
t.Run(tC.desc, func(t *testing.T) {
mock := &grpcTraceServer{}
var l net.Listener
var grpcClientConn *grpc.ClientConn

// prepare the server
{
Expand Down Expand Up @@ -886,7 +889,8 @@ func TestClientInfoInterceptors(t *testing.T) {
require.NoError(t, tt.Shutdown(context.Background()))
}()

grpcClientConn, errClient := gcs.ToClientConn(context.Background(), componenttest.NewNopHost(), tt.TelemetrySettings)
var errClient error
grpcClientConn, errClient = gcs.ToClientConn(context.Background(), componenttest.NewNopHost(), tt.TelemetrySettings)
require.NoError(t, errClient)

cl := ptraceotlp.NewGRPCClient(grpcClientConn)
Expand All @@ -902,6 +906,7 @@ func TestClientInfoInterceptors(t *testing.T) {

// the client address is something like 127.0.0.1:41086
assert.Contains(t, cl.Addr.String(), "127.0.0.1")
assert.NoError(t, grpcClientConn.Close())
})
}
}
Expand Down
17 changes: 17 additions & 0 deletions config/configgrpc/package_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package configgrpc

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"))
}

0 comments on commit 81f9bd9

Please sign in to comment.