Skip to content

Commit 016b46f

Browse files
authored
otelgrpc: Use net.Listen in TestStatsHandler (#4538)
1 parent 23bd4ed commit 016b46f

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_stats_handler_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ package test
1616

1717
import (
1818
"context"
19+
"net"
1920
"testing"
2021

2122
"github.com/stretchr/testify/assert"
2223
"github.com/stretchr/testify/require"
2324
"google.golang.org/grpc"
2425
"google.golang.org/grpc/codes"
25-
"google.golang.org/grpc/test/bufconn"
2626

2727
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
2828
"go.opentelemetry.io/otel/attribute"
@@ -47,9 +47,9 @@ func TestStatsHandler(t *testing.T) {
4747
serverMetricReader := metric.NewManualReader()
4848
serverMP := metric.NewMeterProvider(metric.WithReader(serverMetricReader))
4949

50-
listener := bufconn.Listen(bufSize)
51-
defer listener.Close()
52-
err := newGrpcTest(
50+
listener, err := net.Listen("tcp", "127.0.0.1:0")
51+
require.NoError(t, err, "failed to open port")
52+
err = newGrpcTest(
5353
listener,
5454
[]grpc.DialOption{
5555
grpc.WithStatsHandler(otelgrpc.NewClientHandler(

instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ var wantInstrumentationScope = instrumentation.Scope{
4646
Version: otelgrpc.Version(),
4747
}
4848

49-
const bufSize = 2048
50-
5149
// newGrpcTest creats a grpc server, starts it, and executes all the calls, closes everything down.
5250
func newGrpcTest(listener net.Listener, cOpt []grpc.DialOption, sOpt []grpc.ServerOption) error {
5351
grpcServer := grpc.NewServer(sOpt...)
@@ -108,18 +106,19 @@ func TestInterceptors(t *testing.T) {
108106

109107
listener, err := net.Listen("tcp", "127.0.0.1:0")
110108
require.NoError(t, err, "failed to open port")
111-
err = newGrpcTest(listener, []grpc.DialOption{
112-
//nolint:staticcheck // Interceptors are deprecated and will be removed in the next release.
113-
grpc.WithUnaryInterceptor(otelgrpc.UnaryClientInterceptor(
114-
otelgrpc.WithTracerProvider(clientUnaryTP),
115-
otelgrpc.WithMessageEvents(otelgrpc.ReceivedEvents, otelgrpc.SentEvents),
116-
)),
117-
//nolint:staticcheck // Interceptors are deprecated and will be removed in the next release.
118-
grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor(
119-
otelgrpc.WithTracerProvider(clientStreamTP),
120-
otelgrpc.WithMessageEvents(otelgrpc.ReceivedEvents, otelgrpc.SentEvents),
121-
)),
122-
},
109+
err = newGrpcTest(listener,
110+
[]grpc.DialOption{
111+
//nolint:staticcheck // Interceptors are deprecated and will be removed in the next release.
112+
grpc.WithUnaryInterceptor(otelgrpc.UnaryClientInterceptor(
113+
otelgrpc.WithTracerProvider(clientUnaryTP),
114+
otelgrpc.WithMessageEvents(otelgrpc.ReceivedEvents, otelgrpc.SentEvents),
115+
)),
116+
//nolint:staticcheck // Interceptors are deprecated and will be removed in the next release.
117+
grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor(
118+
otelgrpc.WithTracerProvider(clientStreamTP),
119+
otelgrpc.WithMessageEvents(otelgrpc.ReceivedEvents, otelgrpc.SentEvents),
120+
)),
121+
},
123122
[]grpc.ServerOption{
124123
//nolint:staticcheck // Interceptors are deprecated and will be removed in the next release.
125124
grpc.UnaryInterceptor(otelgrpc.UnaryServerInterceptor(

0 commit comments

Comments
 (0)