Skip to content

Commit

Permalink
rpc_util: various cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
hueypark committed Feb 22, 2024
1 parent 614c2c9 commit 4282fd5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
16 changes: 6 additions & 10 deletions experimental/shared_buffer_pool_test.go
Expand Up @@ -68,12 +68,11 @@ func (s) TestRecvBufferPoolStream(t *testing.T) {
FullDuplexCallF: func(stream testgrpc.TestService_FullDuplexCallServer) error {
for i := 0; i < reqCount; i++ {
preparedMsg := &grpc.PreparedMsg{}
err := preparedMsg.Encode(stream, &testgrpc.StreamingOutputCallResponse{
if err := preparedMsg.Encode(stream, &testgrpc.StreamingOutputCallResponse{
Payload: &testgrpc.Payload{
Body: []byte{'0' + uint8(i)},
},
})
if err != nil {
}); err != nil {
return err
}
stream.SendMsg(preparedMsg)
Expand All @@ -83,7 +82,6 @@ func (s) TestRecvBufferPoolStream(t *testing.T) {
}

pool := &checkBufferPool{}

sopts := []grpc.ServerOption{experimental.RecvBufferPool(pool)}
dopts := []grpc.DialOption{experimental.WithRecvBufferPool(pool)}
if err := ss.Start(sopts, dopts...); err != nil {
Expand All @@ -96,7 +94,7 @@ func (s) TestRecvBufferPoolStream(t *testing.T) {

stream, err := ss.Client.FullDuplexCall(ctx, tc.callOpts...)
if err != nil {
t.Fatalf("ss.Client.FullDuplexCall failed: %f", err)
t.Fatalf("ss.Client.FullDuplexCall failed: %v", err)
}

var ngot int
Expand Down Expand Up @@ -160,7 +158,6 @@ func (s) TestRecvBufferPoolUnary(t *testing.T) {
}

pool := &checkBufferPool{}

sopts := []grpc.ServerOption{experimental.RecvBufferPool(pool)}
dopts := []grpc.DialOption{experimental.WithRecvBufferPool(pool)}
if err := ss.Start(sopts, dopts...); err != nil {
Expand All @@ -173,17 +170,16 @@ func (s) TestRecvBufferPoolUnary(t *testing.T) {

const reqCount = 10
for i := 0; i < reqCount; i++ {
_, err := ss.Client.UnaryCall(
if _, err := ss.Client.UnaryCall(
ctx,
&testgrpc.SimpleRequest{
Payload: &testgrpc.Payload{
Body: make([]byte, largeSize),
},
},
tc.callOpts...,
)
if err != nil {
t.Fatalf("ss.Client.UnaryCall failed: %f", err)
); err != nil {
t.Fatalf("ss.Client.UnaryCall failed: %v", err)
}
}

Expand Down
3 changes: 2 additions & 1 deletion rpc_util.go
Expand Up @@ -795,7 +795,8 @@ func decompress(compressor encoding.Compressor, d []byte, maxReceiveMessageSize
// will read more data if available.
// +MinRead so ReadFrom will not reallocate if size is correct.
//
// TODO: If we ensure that the buffer size is the same as the DecompressedSize, we can also utilize the recv buffer pool here.
// TODO: If we ensure that the buffer size is the same as the DecompressedSize,
// we can also utilize the recv buffer pool here.
buf := bytes.NewBuffer(make([]byte, 0, size+bytes.MinRead))
bytesRead, err := buf.ReadFrom(io.LimitReader(dcReader, int64(maxReceiveMessageSize)+1))
return buf.Bytes(), int(bytesRead), err
Expand Down

0 comments on commit 4282fd5

Please sign in to comment.