From c87c1f49f4c1fc1f68daac612af3fe43e316356f Mon Sep 17 00:00:00 2001 From: yuqitao Date: Tue, 16 Apr 2019 22:23:28 +0800 Subject: [PATCH 1/2] `FailFast(false)`, return helpful error message when context is time out --- picker_wrapper.go | 8 ++++++++ test/end2end_test.go | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/picker_wrapper.go b/picker_wrapper.go index f9625496c403..45baa2ae13da 100644 --- a/picker_wrapper.go +++ b/picker_wrapper.go @@ -120,6 +120,14 @@ func (bp *pickerWrapper) pick(ctx context.Context, failfast bool, opts balancer. bp.mu.Unlock() select { case <-ctx.Done(): + if connectionErr := bp.connectionError(); connectionErr != nil { + switch ctx.Err() { + case context.DeadlineExceeded: + return nil, nil, status.Errorf(codes.DeadlineExceeded, "latest connection error: %v", connectionErr) + case context.Canceled: + return nil, nil, status.Errorf(codes.Canceled, "latest connection error: %v", connectionErr) + } + } return nil, nil, ctx.Err() case <-ch: } diff --git a/test/end2end_test.go b/test/end2end_test.go index 6d81b2d22f15..1de6ac0e7efc 100644 --- a/test/end2end_test.go +++ b/test/end2end_test.go @@ -6642,6 +6642,29 @@ func (s) TestFailFastRPCErrorOnBadCertificates(t *testing.T) { te.t.Fatalf("TestService/EmptyCall(_, _) = _, %v, want err.Error() contains %q", err, clientAlwaysFailCredErrorMsg) } +func (s) TestWaitForReadyRPCErrorOnBadCertificates(t *testing.T) { + te := newTest(t, env{name: "bad-cred", network: "tcp", security: "clientAlwaysFailCred", balancer: "round_robin"}) + te.startServer(&testServer{security: te.e.security}) + defer te.tearDown() + + opts := []grpc.DialOption{grpc.WithTransportCredentials(clientAlwaysFailCred{})} + dctx, dcancel := context.WithTimeout(context.Background(), 10*time.Second) + defer dcancel() + cc, err := grpc.DialContext(dctx, te.srvAddr, opts...) + if err != nil { + t.Fatalf("Dial(_) = %v, want %v", err, nil) + } + defer cc.Close() + + tc := testpb.NewTestServiceClient(cc) + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + if _, err = tc.EmptyCall(ctx, &testpb.Empty{}, grpc.WaitForReady(true)); strings.Contains(err.Error(), clientAlwaysFailCredErrorMsg) { + return + } + te.t.Fatalf("TestService/EmptyCall(_, _) = _, %v, want err.Error() contains %q", err, clientAlwaysFailCredErrorMsg) +} + func (s) TestRPCTimeout(t *testing.T) { for _, e := range listTestEnv() { testRPCTimeout(t, e) From 308b8b9e5a4a9864a72d7b5f23b9e969cbc9f61c Mon Sep 17 00:00:00 2001 From: Menghan Li Date: Mon, 29 Apr 2019 10:09:35 -0700 Subject: [PATCH 2/2] 1 second test timeout --- test/end2end_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/end2end_test.go b/test/end2end_test.go index 1de6ac0e7efc..8513d6653fb3 100644 --- a/test/end2end_test.go +++ b/test/end2end_test.go @@ -6657,7 +6657,7 @@ func (s) TestWaitForReadyRPCErrorOnBadCertificates(t *testing.T) { defer cc.Close() tc := testpb.NewTestServiceClient(cc) - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) defer cancel() if _, err = tc.EmptyCall(ctx, &testpb.Empty{}, grpc.WaitForReady(true)); strings.Contains(err.Error(), clientAlwaysFailCredErrorMsg) { return