Skip to content

Commit

Permalink
Add BenchmarkStreamClientInterceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
pellared committed Nov 10, 2023
1 parent e4d0b84 commit 46b73b1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Expand Up @@ -46,7 +46,7 @@ var wantInstrumentationScope = instrumentation.Scope{
}

// newGrpcTest creats a grpc server, starts it, and returns the client, closes everything down during test cleanup.
func newGrpcTest(t *testing.T, listener net.Listener, cOpt []grpc.DialOption, sOpt []grpc.ServerOption) pb.TestServiceClient {
func newGrpcTest(t testing.TB, listener net.Listener, cOpt []grpc.DialOption, sOpt []grpc.ServerOption) pb.TestServiceClient {
grpcServer := grpc.NewServer(sOpt...)
pb.RegisterTestServiceServer(grpcServer, interop.NewTestServer())
errCh := make(chan error)
Expand Down
Expand Up @@ -40,6 +40,7 @@ import (
"google.golang.org/grpc"
grpc_codes "google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/interop"
"google.golang.org/grpc/interop/grpc_testing"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -1128,3 +1129,20 @@ func assertServerMetrics(t *testing.T, reader metric.Reader, serviceName, name s
require.Len(t, rm.ScopeMetrics, 1)
metricdatatest.AssertEqual(t, want, rm.ScopeMetrics[0], metricdatatest.IgnoreTimestamp(), metricdatatest.IgnoreValue())
}

func BenchmarkStreamClientInterceptor(b *testing.B) {
listener, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(b, err, "failed to open port")
client := newGrpcTest(b, listener,
[]grpc.DialOption{
//nolint:staticcheck // Interceptors are deprecated and will be removed in the next release.
grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor()),
},
[]grpc.ServerOption{},
)

b.ResetTimer()
for i := 0; i < b.N; i++ {
interop.DoClientStreaming(client)
}
}

0 comments on commit 46b73b1

Please sign in to comment.