Skip to content

Commit

Permalink
Resolve address before sending the RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
arjan-bal committed Dec 20, 2024
1 parent e830617 commit a3fb3dd
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions test/creds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand All @@ -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)

Check failure on line 268 in test/creds_test.go

View workflow job for this annotation

GitHub Actions / tests (vet, 1.22)

this value of cancel is never used (SA4006)
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)
Expand Down

0 comments on commit a3fb3dd

Please sign in to comment.