Skip to content

Make the generated code return nil intead of io.EOF when everything succ... #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/go_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ void PrintClientMethodImpl(google::protobuf::io::Printer* printer,
"\t}\n"
"\t// Read EOF.\n"
"\tif err := x.ClientStream.RecvProto(m); err == io.EOF {\n"
"\t\treturn m, io.EOF\n"
"\t\treturn m, nil\n"
"\t}\n"
"\t// gRPC protocol violation.\n"
"\treturn m, fmt.Errorf(\"Violate gRPC client streaming protocol: no "
Expand Down
36 changes: 18 additions & 18 deletions interop/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,20 @@ var (
serverHost = flag.String("server_host", "127.0.0.1", "The server host name")
serverPort = flag.Int("server_port", 10000, "The server port number")
tlsServerName = flag.String("tls_server_name", "x.test.youtube.com", "The server name use to verify the hostname returned by TLS handshake")
testCase = flag.String("test_case", "large_unary", "The RPC method to be tested: large_unary|empty_unary|client_streaming|server_streaming|ping_pong|all")
testCase = flag.String("test_case", "large_unary",
`Configure different test cases. Valid options are:
empty_unary : empty (zero bytes) request and response;
large_unary : single request and (large) response;
client_streaming : request streaming with single response;
server_streaming : single request with response streaming;
ping_pong : full-duplex streaming`)
)

var (
reqSizes = []int{27182, 8, 1828, 45904}
respSizes = []int{31415, 9, 2653, 58979}
reqSizes = []int{27182, 8, 1828, 45904}
respSizes = []int{31415, 9, 2653, 58979}
largeReqSize = 271828
largeRespSize = 314159
)

func newPayload(t testpb.PayloadType, size int) *testpb.Payload {
Expand Down Expand Up @@ -90,12 +98,10 @@ func doEmptyUnaryCall(tc testpb.TestServiceClient) {
}

func doLargeUnaryCall(tc testpb.TestServiceClient) {
argSize := 271828
respSize := 314159
pl := newPayload(testpb.PayloadType_COMPRESSABLE, argSize)
pl := newPayload(testpb.PayloadType_COMPRESSABLE, largeReqSize)
req := &testpb.SimpleRequest{
ResponseType: testpb.PayloadType_COMPRESSABLE.Enum(),
ResponseSize: proto.Int32(int32(respSize)),
ResponseSize: proto.Int32(int32(largeRespSize)),
Payload: pl,
}
reply, err := tc.UnaryCall(context.Background(), req)
Expand All @@ -104,8 +110,8 @@ func doLargeUnaryCall(tc testpb.TestServiceClient) {
}
t := reply.GetPayload().GetType()
s := len(reply.GetPayload().GetBody())
if t != testpb.PayloadType_COMPRESSABLE || s != respSize {
log.Fatalf("Got the reply with type %d len %d; want %d, %d", t, s, testpb.PayloadType_COMPRESSABLE, respSize)
if t != testpb.PayloadType_COMPRESSABLE || s != largeRespSize {
log.Fatalf("Got the reply with type %d len %d; want %d, %d", t, s, testpb.PayloadType_COMPRESSABLE, largeRespSize)
}
}

Expand All @@ -128,8 +134,8 @@ func doClientStreaming(tc testpb.TestServiceClient) {

}
reply, err := stream.CloseAndRecv()
if err != io.EOF {
log.Fatalf("%v.CloseAndRecv() got error %v, want %v", stream, err, io.EOF)
if err != nil {
log.Fatalf("%v.CloseAndRecv() got error %v, want %v", stream, err, nil)
}
if reply.GetAggregatedPayloadSize() != int32(sum) {
log.Fatalf("%v.CloseAndRecv().GetAggregatePayloadSize() = %v; want %v", stream, reply.GetAggregatedPayloadSize(), sum)
Expand Down Expand Up @@ -236,7 +242,7 @@ func main() {
var err error
creds, err = credentials.NewClientTLSFromFile(*caFile, sn)
if err != nil {
log.Fatalf("Failed to create credentials %v", err)
log.Fatalf("Failed to create TLS credentials %v", err)
}
} else {
creds = credentials.NewClientTLSFromCert(nil, sn)
Expand All @@ -260,12 +266,6 @@ func main() {
doServerStreaming(tc)
case "ping_pong":
doPingPong(tc)
case "all":
doEmptyUnaryCall(tc)
doLargeUnaryCall(tc)
doClientStreaming(tc)
doServerStreaming(tc)
doPingPong(tc)
default:
log.Fatal("Unsupported test case: ", *testCase)
}
Expand Down
2 changes: 1 addition & 1 deletion interop/grpc_testing/test.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test/end2end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,8 @@ func TestClientStreaming(t *testing.T) {
sum += s
}
reply, err := stream.CloseAndRecv()
if err != io.EOF {
t.Fatalf("%v.CloseAndRecv() got error %v, want %v", stream, err, io.EOF)
if err != nil {
t.Fatalf("%v.CloseAndRecv() got error %v, want %v", stream, err, nil)
}
if reply.GetAggregatedPayloadSize() != int32(sum) {
t.Fatalf("%v.CloseAndRecv().GetAggregatePayloadSize() = %v; want %v", stream, reply.GetAggregatedPayloadSize(), sum)
Expand Down
2 changes: 1 addition & 1 deletion test/grpc_testing/test.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.