Skip to content

Commit

Permalink
transport: fix flaky TestGRPCHook
Browse files Browse the repository at this point in the history
Pass the grpc.WithBlock option to Dial to ensure the context
cancellation in expectedDialer causes the Dial to fail.

Increase the context timeout as an extra defensive measure.

TestGRPCHook ran 10,000,000 times without failure.

Fixes googleapis#411

Change-Id: Ifd39231ce780a48cca761559c8286c91b76b87b0
Reviewed-on: https://code-review.googlesource.com/c/google-api-go-client/+/48770
Reviewed-by: kokoro <[email protected]>
Reviewed-by: Jean de Klerk <[email protected]>
  • Loading branch information
escholtz authored and jeanbza committed Nov 26, 2019
1 parent 61e83cb commit f31831e
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions transport/grpc/dial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

// Check that user optioned grpc.WithDialer option overwrites App Engine dialer
func TestGRPCHook(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Millisecond)
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
expected := false

appengineDialerHook = (func(ctx context.Context) grpc.DialOption {
Expand All @@ -42,15 +42,14 @@ func TestGRPCHook(t *testing.T) {
conn, err := Dial(ctx,
option.WithTokenSource(oauth2.StaticTokenSource(nil)), // No creds.
option.WithGRPCDialOption(expectedDialer),
option.WithEndpoint("example.google.com:443"))
if err != nil {
t.Errorf("DialGRPC: error %v, want nil", err)
option.WithGRPCDialOption(grpc.WithBlock()))
if err != context.Canceled {
t.Errorf("got %v, want %v", err, context.Canceled)
}
if conn != nil {
conn.Close()
t.Error("got valid conn, want nil")
}
defer conn.Close()

// gRPC doesn't connect before the first call.
grpc.Invoke(ctx, "foo", nil, nil, conn)

if !expected {
t.Error("expected a call to expected dialer, didn't get one")
}
Expand Down

0 comments on commit f31831e

Please sign in to comment.