From 9c6754e004ace2c5d9cb01c10a12486313f4d3a6 Mon Sep 17 00:00:00 2001 From: iamqizhao Date: Mon, 23 Mar 2015 11:47:27 -0700 Subject: [PATCH 1/2] fix a malformed error status --- call.go | 2 +- test/end2end_test.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/call.go b/call.go index 13c8b821815..32ca7eb3e9f 100644 --- a/call.go +++ b/call.go @@ -147,7 +147,7 @@ func Invoke(ctx context.Context, method string, args, reply proto.Message, cc *C // This was a retry; return the error from the last attempt. return toRPCErr(lastErr) } - return Errorf(codes.Internal, "%v", err) + return toRPCErr(err) } stream, err = sendRPC(ctx, callHdr, t, args, topts) if err != nil { diff --git a/test/end2end_test.go b/test/end2end_test.go index 504e7f6ffa8..7f1b7e1b483 100644 --- a/test/end2end_test.go +++ b/test/end2end_test.go @@ -301,6 +301,17 @@ func setUp(useTLS bool, maxStream uint32) (s *grpc.Server, tc testpb.TestService return } +func TestTimeoutOnDeadServer(t *testing.T) { + s, tc := setUp(false, math.MaxUint32) + s.Stop() + // Set a minimal deadline to make sure the context times out in the 1st + // invoke of ClientConn.wait. + ctx, _ := context.WithTimeout(context.Background(), time.Nanosecond) + if _, err := tc.EmptyCall(ctx, &testpb.Empty{}); grpc.Code(err) != codes.DeadlineExceeded { + t.Fatalf("TestService/EmptyCall(%v, _) = _, error %v, want _, error code: %d", ctx, err, codes.DeadlineExceeded) + } +} + func TestEmptyUnary(t *testing.T) { s, tc := setUp(true, math.MaxUint32) defer s.Stop() From 591c1176bcc131b6e2761e138621d0a77276de75 Mon Sep 17 00:00:00 2001 From: iamqizhao Date: Mon, 23 Mar 2015 12:31:20 -0700 Subject: [PATCH 2/2] modify a comment --- test/end2end_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/end2end_test.go b/test/end2end_test.go index 7f1b7e1b483..4b3c1db6d35 100644 --- a/test/end2end_test.go +++ b/test/end2end_test.go @@ -304,9 +304,10 @@ func setUp(useTLS bool, maxStream uint32) (s *grpc.Server, tc testpb.TestService func TestTimeoutOnDeadServer(t *testing.T) { s, tc := setUp(false, math.MaxUint32) s.Stop() - // Set a minimal deadline to make sure the context times out in the 1st - // invoke of ClientConn.wait. - ctx, _ := context.WithTimeout(context.Background(), time.Nanosecond) + // Set -1 as the timeout to make sure if transportMonitor gets error + // notification in time the failure path of the 1st invoke of + // ClientConn.wait hits the deadline exceeded error. + ctx, _ := context.WithTimeout(context.Background(), -1) if _, err := tc.EmptyCall(ctx, &testpb.Empty{}); grpc.Code(err) != codes.DeadlineExceeded { t.Fatalf("TestService/EmptyCall(%v, _) = _, error %v, want _, error code: %d", ctx, err, codes.DeadlineExceeded) }