From 4596c55b7ad16a68ac82e3f75318fedb649bb8ee Mon Sep 17 00:00:00 2001 From: iamqizhao Date: Tue, 25 Oct 2016 15:32:12 -0700 Subject: [PATCH] Use the correct error in defer call --- call.go | 7 +++---- test/end2end_test.go | 22 +++++++++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/call.go b/call.go index 788b3d92..772c817e 100644 --- a/call.go +++ b/call.go @@ -49,9 +49,8 @@ import ( // On error, it returns the error and indicates whether the call should be retried. // // TODO(zhaoq): Check whether the received message sequence is valid. -func recvResponse(dopts dialOptions, t transport.ClientTransport, c *callInfo, stream *transport.Stream, reply interface{}) error { +func recvResponse(dopts dialOptions, t transport.ClientTransport, c *callInfo, stream *transport.Stream, reply interface{}) (err error) { // Try to acquire header metadata from the server if there is any. - var err error defer func() { if err != nil { if _, ok := err.(transport.ConnectionError); !ok { @@ -61,7 +60,7 @@ func recvResponse(dopts dialOptions, t transport.ClientTransport, c *callInfo, s }() c.headerMD, err = stream.Header() if err != nil { - return err + return } p := &parser{r: stream} for { @@ -69,7 +68,7 @@ func recvResponse(dopts dialOptions, t transport.ClientTransport, c *callInfo, s if err == io.EOF { break } - return err + return } } c.trailerMD = stream.Trailer() diff --git a/test/end2end_test.go b/test/end2end_test.go index d12a1f99..6b644bb3 100644 --- a/test/end2end_test.go +++ b/test/end2end_test.go @@ -2504,7 +2504,7 @@ func testStreamsQuotaRecovery(t *testing.T, e env) { cc := te.clientConn() tc := testpb.NewTestServiceClient(cc) - ctx, cancel := context.WithCancel(context.Background()) + ctx, _ := context.WithCancel(context.Background()) if _, err := tc.StreamingInputCall(ctx); err != nil { t.Fatalf("%v.StreamingInputCall(_) = _, %v, want _, ", tc, err) } @@ -2522,18 +2522,26 @@ func testStreamsQuotaRecovery(t *testing.T, e env) { } t.Fatalf("%v.StreamingInputCall(_) = _, %v, want _, %s", tc, err, codes.DeadlineExceeded) } - cancel() var wg sync.WaitGroup - for i := 0; i < 100; i++ { + for i := 0; i < 10; i++ { wg.Add(1) go func() { defer wg.Done() - ctx, cancel := context.WithCancel(context.Background()) - if _, err := tc.StreamingInputCall(ctx); err != nil { - t.Errorf("%v.StreamingInputCall(_) = _, %v, want _, ", tc, err) + payload, err := newPayload(testpb.PayloadType_COMPRESSABLE, 314) + if err != nil { + t.Fatal(err) + } + req := &testpb.SimpleRequest{ + ResponseType: testpb.PayloadType_COMPRESSABLE.Enum(), + ResponseSize: proto.Int32(1592), + Payload: payload, + } + // No rpc should go through due to the max streams limit. + ctx, _ := context.WithTimeout(context.Background(), 10*time.Millisecond) + if _, err := tc.UnaryCall(ctx, req, grpc.FailFast(false)); grpc.Code(err) != codes.DeadlineExceeded { + t.Errorf("TestService/UnaryCall(_, _) = _, %v, want _, %s", err, codes.DeadlineExceeded) } - cancel() }() } wg.Wait()