transport: fix flaky TestGRPCHook

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 #411

Change-Id: Ifd39231ce780a48cca761559c8286c91b76b87b0
Reviewed-on: https://code-review.googlesource.com/c/google-api-go-client/+/48770
Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jean de Klerk <deklerk@google.com>
diff --git a/transport/grpc/dial_test.go b/transport/grpc/dial_test.go
index 34ef352..c850ce6 100644
--- a/transport/grpc/dial_test.go
+++ b/transport/grpc/dial_test.go
@@ -19,7 +19,7 @@
 
 // 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 {
@@ -42,15 +42,14 @@
 	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)
 	}
-	defer conn.Close()
-
-	// gRPC doesn't connect before the first call.
-	grpc.Invoke(ctx, "foo", nil, nil, conn)
-
+	if conn != nil {
+		conn.Close()
+		t.Error("got valid conn, want nil")
+	}
 	if !expected {
 		t.Error("expected a call to expected dialer, didn't get one")
 	}