Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx committed Sep 21, 2022
1 parent 98ec705 commit 5d6a29d
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions tests/integration/v3_grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1937,30 +1937,46 @@ func TestV3AdditionalGRPCOptions(t *testing.T) {
valueSize int
expectError error
}{
{"requests will get a gRPC error because it's larger than gRPC MaxRecvMsgSize",
8 * 1024 * 1024, nil, 9 * 1024 * 1024, status.Errorf(codes.ResourceExhausted, "grpc: received message larger than max")},
{"requests will get an etcd custom gRPC error because it's larger than MaxRequestBytes",
8 * 1024 * 1024, []grpc.ServerOption{grpc.MaxRecvMsgSize(10 * 1024 * 1024)}, 9 * 1024 * 1024, rpctypes.ErrGRPCRequestTooLarge},
{
name: "requests will get a gRPC error because it's larger than gRPC MaxRecvMsgSize",
maxRequestBytes: 8 * 1024 * 1024,
grpcOpts: nil,
valueSize: 9 * 1024 * 1024,
expectError: status.Errorf(codes.ResourceExhausted, "grpc: received message larger than max"),
},
{
name: "requests will get an etcd custom gRPC error because it's larger than MaxRequestBytes",
maxRequestBytes: 8 * 1024 * 1024,
grpcOpts: []grpc.ServerOption{grpc.MaxRecvMsgSize(10 * 1024 * 1024)},
valueSize: 9 * 1024 * 1024,
expectError: rpctypes.ErrGRPCRequestTooLarge,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
clus := integration.NewCluster(t, &integration.ClusterConfig{Size: 1, MaxRequestBytes: test.maxRequestBytes, ClientMaxCallSendMsgSize: 12 * 1024 * 1024, GRPCAdditionalServerOptions: test.grpcOpts})
clus := integration.NewCluster(t, &integration.ClusterConfig{
Size: 1,
MaxRequestBytes: test.maxRequestBytes,
ClientMaxCallSendMsgSize: 12 * 1024 * 1024,
GRPCAdditionalServerOptions: test.grpcOpts,
})
defer clus.Terminate(t)
kvcli := integration.ToGRPC(clus.Client(0)).KV
reqput := &pb.PutRequest{Key: []byte("foo"), Value: make([]byte, test.valueSize)}
_, err := kvcli.Put(context.TODO(), reqput)
if _, ok := err.(rpctypes.EtcdError); ok {
if err.Error() != status.Convert(test.expectError).Message() {
t.Errorf("expected %v, got %v", status.Convert(test.expectError).Message(), err.Error())
if _, err := kvcli.Put(context.TODO(), reqput); err != nil {
if _, ok := err.(rpctypes.EtcdError); ok {
if err.Error() != status.Convert(test.expectError).Message() {
t.Errorf("expected %v, got %v", status.Convert(test.expectError).Message(), err.Error())
}
} else if !strings.HasPrefix(err.Error(), test.expectError.Error()) {
t.Errorf("expected error starting with '%s', got '%s'", test.expectError.Error(), err.Error())
}
} else if err != nil && !strings.HasPrefix(err.Error(), test.expectError.Error()) {
t.Errorf("expected error starting with '%s', got '%s'", test.expectError.Error(), err.Error())
}
// request went through, expect large response back from server
if test.expectError == nil {
reqget := &pb.RangeRequest{Key: []byte("foo")}
// limit receive call size with original value + gRPC overhead bytes
_, err = kvcli.Range(context.TODO(), reqget, grpc.MaxCallRecvMsgSize(test.valueSize+512*1024))
_, err := kvcli.Range(context.TODO(), reqget, grpc.MaxCallRecvMsgSize(test.valueSize+512*1024))
if err != nil {
t.Errorf("range expected no error, got %v", err)
}
Expand Down

0 comments on commit 5d6a29d

Please sign in to comment.