diff --git a/test/creds_test.go b/test/creds_test.go index 983437758981..1620d7b023d2 100644 --- a/test/creds_test.go +++ b/test/creds_test.go @@ -32,7 +32,6 @@ import ( "google.golang.org/grpc/connectivity" "google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials/insecure" - "google.golang.org/grpc/internal/resolver/dns" "google.golang.org/grpc/internal/testutils" "google.golang.org/grpc/metadata" "google.golang.org/grpc/resolver" @@ -244,28 +243,13 @@ func (s) TestFailFastRPCErrorOnBadCertificates(t *testing.T) { defer cc.Close() tc := testgrpc.NewTestServiceClient(cc) - for i := 0; i < 1000; i++ { - // This loop runs for at most 1 second. The first several RPCs will fail - // with Unavailable because the connection hasn't started. When the - // first connection failed with creds error, the next RPC should also - // fail with the expected error. - if _, err = tc.EmptyCall(ctx, &testpb.Empty{}); strings.Contains(err.Error(), clientAlwaysFailCredErrorMsg) { - return - } - time.Sleep(time.Millisecond) + if _, err = tc.EmptyCall(ctx, &testpb.Empty{}); strings.Contains(err.Error(), clientAlwaysFailCredErrorMsg) { + return } te.t.Fatalf("TestService/EmptyCall(_, _) = _, %v, want err.Error() contains %q", err, clientAlwaysFailCredErrorMsg) } func (s) TestWaitForReadyRPCErrorOnBadCertificates(t *testing.T) { - // SRV lookup is enabled because of the grpclb import in other test files. - // It is disabled since it can take more than 10 millis causing test - // flakiness. - originalEnableSRV := dns.EnableSRVLookups - defer func() { - dns.EnableSRVLookups = originalEnableSRV - }() - dns.EnableSRVLookups = false te := newTest(t, env{name: "bad-cred", network: "tcp", security: "empty", balancer: "round_robin"}) te.startServer(&testServer{security: te.e.security}) defer te.tearDown() @@ -277,8 +261,15 @@ func (s) TestWaitForReadyRPCErrorOnBadCertificates(t *testing.T) { } defer cc.Close() + // The DNS resolver may take more than defaultTestShortTimeout, we let the + // channel enter TransientFailure signalling that the first resolver state + // has been produced. + cc.Connect() + ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) + testutils.AwaitState(ctx, t, cc, connectivity.TransientFailure) + tc := testgrpc.NewTestServiceClient(cc) - ctx, cancel := context.WithTimeout(context.Background(), defaultTestShortTimeout) + ctx, cancel = context.WithTimeout(context.Background(), defaultTestShortTimeout) defer cancel() if _, err = tc.EmptyCall(ctx, &testpb.Empty{}, grpc.WaitForReady(true)); !strings.Contains(err.Error(), clientAlwaysFailCredErrorMsg) { t.Fatalf("TestService/EmptyCall(_, _) = _, %v, want err.Error() contains %q", err, clientAlwaysFailCredErrorMsg)