From c477cb3b147be4bc47e5e3f28564b98546077a29 Mon Sep 17 00:00:00 2001 From: iamqizhao Date: Thu, 30 Jun 2016 14:26:31 -0700 Subject: [PATCH] fix the flaky test --- test/end2end_test.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/end2end_test.go b/test/end2end_test.go index b65e505f..326b8869 100644 --- a/test/end2end_test.go +++ b/test/end2end_test.go @@ -590,16 +590,18 @@ func testFailFast(t *testing.T, e env) { } // Stop the server and tear down all the exisiting connections. te.srv.Stop() - // Issue an RPC to make sure the server teardown is propagated to the client already. - ctx, _ := context.WithTimeout(context.Background(), time.Millisecond) - if _, err := tc.EmptyCall(ctx, &testpb.Empty{}, grpc.FailFast(false)); grpc.Code(err) != codes.DeadlineExceeded { - t.Fatalf("TestService/EmptyCall(%v, _) = _, %v, want _, error code: %d", ctx, err, codes.DeadlineExceeded) + // Loop until the server teardown is propagated to the client. + for { + if _, err := tc.EmptyCall(context.Background(), &testpb.Empty{}); grpc.Code(err) == codes.Unavailable { + break + } + time.Sleep(10 * time.Millisecond) } // The client keeps reconnecting and ongoing fail-fast RPCs should fail with code.Unavailable. if _, err := tc.EmptyCall(context.Background(), &testpb.Empty{}); grpc.Code(err) != codes.Unavailable { t.Fatalf("TestService/EmptyCall(_, _, _) = _, %v, want _, error code: %d", err, codes.Unavailable) } - if _, err := tc.StreamingInputCall(ctx); grpc.Code(err) != codes.Unavailable { + if _, err := tc.StreamingInputCall(context.Background()); grpc.Code(err) != codes.Unavailable { t.Fatalf("TestService/StreamingInputCall(_) = _, %v, want _, error code: %d", err, codes.Unavailable) }