Change interop server to support response_status field.
This commit is contained in:
@ -456,9 +456,9 @@ func DoCancelAfterFirstResponse(tc testpb.TestServiceClient) {
|
|||||||
|
|
||||||
// DoStatusCodeAndMessage checks that the status code is propagated back to the client.
|
// DoStatusCodeAndMessage checks that the status code is propagated back to the client.
|
||||||
func DoStatusCodeAndMessage(tc testpb.TestServiceClient) {
|
func DoStatusCodeAndMessage(tc testpb.TestServiceClient) {
|
||||||
|
var code int32 = 2
|
||||||
|
msg := "test status message"
|
||||||
// Test UnaryCall.
|
// Test UnaryCall.
|
||||||
var code int32 = 2
|
|
||||||
msg := "test status message"
|
|
||||||
respStatus := &testpb.EchoStatus{
|
respStatus := &testpb.EchoStatus{
|
||||||
Code: &code,
|
Code: &code,
|
||||||
Message: &msg,
|
Message: &msg,
|
||||||
@ -467,7 +467,7 @@ func DoStatusCodeAndMessage(tc testpb.TestServiceClient) {
|
|||||||
ResponseStatus: respStatus,
|
ResponseStatus: respStatus,
|
||||||
}
|
}
|
||||||
_, err := tc.UnaryCall(context.Background(), req)
|
_, err := tc.UnaryCall(context.Background(), req)
|
||||||
if grpc.Code(err) != 2 {
|
if grpc.Code(err) != codes.Code(code) {
|
||||||
grpclog.Fatalf("/TestService/UnaryCall RPC compleled with error code %d, want %d", grpc.Code(err), code)
|
grpclog.Fatalf("/TestService/UnaryCall RPC compleled with error code %d, want %d", grpc.Code(err), code)
|
||||||
}
|
}
|
||||||
if err.Error() != msg {
|
if err.Error() != msg {
|
||||||
@ -485,7 +485,7 @@ func DoStatusCodeAndMessage(tc testpb.TestServiceClient) {
|
|||||||
grpclog.Fatalf("%v.Send(%v) = %v", stream, stream_req, err)
|
grpclog.Fatalf("%v.Send(%v) = %v", stream, stream_req, err)
|
||||||
}
|
}
|
||||||
err = stream.CloseSend()
|
err = stream.CloseSend()
|
||||||
if grpc.Code(err) != 2 {
|
if grpc.Code(err) != codes.Code(code) {
|
||||||
grpclog.Fatalf("%v compleled with error code %d, want %d", stream, grpc.Code(err), code)
|
grpclog.Fatalf("%v compleled with error code %d, want %d", stream, grpc.Code(err), code)
|
||||||
}
|
}
|
||||||
if err.Error() != msg {
|
if err.Error() != msg {
|
||||||
@ -524,6 +524,10 @@ func serverNewPayload(t testpb.PayloadType, size int32) (*testpb.Payload, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *testServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
|
func (s *testServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
|
||||||
|
resp := in.GetResponseStatus()
|
||||||
|
if *resp.Code != 0 {
|
||||||
|
return nil, grpc.Errorf(codes.Code(*resp.Code), *resp.Message)
|
||||||
|
}
|
||||||
pl, err := serverNewPayload(in.GetResponseType(), in.GetResponseSize())
|
pl, err := serverNewPayload(in.GetResponseType(), in.GetResponseSize())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -534,6 +538,10 @@ func (s *testServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (*
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *testServer) StreamingOutputCall(args *testpb.StreamingOutputCallRequest, stream testpb.TestService_StreamingOutputCallServer) error {
|
func (s *testServer) StreamingOutputCall(args *testpb.StreamingOutputCallRequest, stream testpb.TestService_StreamingOutputCallServer) error {
|
||||||
|
resp := args.GetResponseStatus()
|
||||||
|
if *resp.Code != 0 {
|
||||||
|
return grpc.Errorf(codes.Code(*resp.Code), *resp.Message)
|
||||||
|
}
|
||||||
cs := args.GetResponseParameters()
|
cs := args.GetResponseParameters()
|
||||||
for _, c := range cs {
|
for _, c := range cs {
|
||||||
if us := c.GetIntervalUs(); us > 0 {
|
if us := c.GetIntervalUs(); us > 0 {
|
||||||
|
Reference in New Issue
Block a user