TestInvokeLargeErr verifies an invocation of ClientConn.Invoke() where the server returns a really large error message.
(t *testing.T)
| 51 | // TestInvokeLargeErr verifies an invocation of ClientConn.Invoke() where the |
| 52 | // server returns a really large error message. |
| 53 | func (s) TestInvokeLargeErr(t *testing.T) { |
| 54 | largeErrorStr := strings.Repeat("A", 1024*1024) |
| 55 | ss := &stubserver.StubServer{ |
| 56 | EmptyCallF: func(context.Context, *testpb.Empty) (*testpb.Empty, error) { |
| 57 | return &testpb.Empty{}, status.Error(codes.Internal, largeErrorStr) |
| 58 | }, |
| 59 | } |
| 60 | if err := ss.Start(nil); err != nil { |
| 61 | t.Fatalf("Failed to start stub server: %v", err) |
| 62 | } |
| 63 | defer ss.Stop() |
| 64 | |
| 65 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 66 | defer cancel() |
| 67 | err := ss.CC.Invoke(ctx, "/grpc.testing.TestService/EmptyCall", &testpb.Empty{}, &testpb.Empty{}) |
| 68 | if err == nil { |
| 69 | t.Fatal("grpc.Invoke(\"/grpc.testing.TestService/EmptyCall\") succeeded when expected to fail") |
| 70 | } |
| 71 | st, ok := status.FromError(err) |
| 72 | if !ok { |
| 73 | t.Fatal("grpc.Invoke(\"/grpc.testing.TestService/EmptyCall\") received non-status error") |
| 74 | } |
| 75 | if status.Code(err) != codes.Internal || st.Message() != largeErrorStr { |
| 76 | t.Fatalf("grpc.Invoke(\"/grpc.testing.TestService/EmptyCall\") failed with error: %v, want an error of code %d and desc size %d", err, codes.Internal, len(largeErrorStr)) |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | // TestInvokeErrorSpecialChars tests an invocation of ClientConn.Invoke() and |
| 81 | // verifies that error messages don't get mangled. |