Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alts: Add retry loop when making RPC in ALTS's TestFullHandshake. #6183

Merged
merged 5 commits into from
Apr 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions credentials/alts/alts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (

"github.com/golang/protobuf/proto"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/alts/internal/handshaker/service"
altsgrpc "google.golang.org/grpc/credentials/alts/internal/proto/grpc_gcp"
altspb "google.golang.org/grpc/credentials/alts/internal/proto/grpc_gcp"
Expand All @@ -39,6 +40,12 @@ import (
"google.golang.org/grpc/internal/testutils"
testgrpc "google.golang.org/grpc/interop/grpc_testing"
testpb "google.golang.org/grpc/interop/grpc_testing"
"google.golang.org/grpc/status"
)

const (
defaultTestLongTimeout = 10 * time.Second
defaultTestShortTimeout = 10 * time.Millisecond
)

type s struct {
Expand Down Expand Up @@ -301,7 +308,7 @@ func (s) TestCheckRPCVersions(t *testing.T) {
// TestFullHandshake performs a full ALTS handshake between a test client and
// server, where both client and server offload to a local, fake handshaker
// service.
func TestFullHandshake(t *testing.T) {
func (s) TestFullHandshake(t *testing.T) {
// If GOMAXPROCS is set to less than 2, do not run this test. This test
// requires at least 2 goroutines to succeed (one goroutine where a
// server listens, another goroutine where a client runs).
Expand Down Expand Up @@ -334,11 +341,19 @@ func TestFullHandshake(t *testing.T) {
t.Fatalf("grpc.Dial(%v) failed: %v", serverAddress, err)
}
defer conn.Close()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), defaultTestLongTimeout)
defer cancel()
c := testgrpc.NewTestServiceClient(conn)
if _, err = c.UnaryCall(ctx, &testpb.SimpleRequest{}, grpc.WaitForReady(true)); err != nil {
t.Errorf("c.UnaryCall() failed: %v", err)
for ; ctx.Err() == nil; <-time.After(defaultTestShortTimeout) {
_, err = c.UnaryCall(ctx, &testpb.SimpleRequest{})
if err == nil {
break
}
if code := status.Code(err); code == codes.Unavailable {
// The server is not ready yet. Try again.
continue
}
t.Fatalf("c.UnaryCall() failed: %v", err)
}

// Close open connections to the fake handshaker service.
Expand Down