diff --git a/Documentation/encoding.md b/Documentation/encoding.md index cce9384f71e0..00e19cc88eed 100644 --- a/Documentation/encoding.md +++ b/Documentation/encoding.md @@ -57,7 +57,7 @@ As a reminder, all `CallOption`s may be converted into `DialOption`s that become the default for all RPCs sent through a client using `grpc.WithDefaultCallOptions`: ```go - myclient := grpc.Dial(ctx, target, grpc.WithDefaultCallOptions(grpc.CallContentSubtype("mycodec"))) + myclient := grpc.NewClient(target, grpc.WithDefaultCallOptions(grpc.CallContentSubtype("mycodec"))) ``` When specified in either of these ways, messages will be encoded using this @@ -132,7 +132,7 @@ As a reminder, all `CallOption`s may be converted into `DialOption`s that become the default for all RPCs sent through a client using `grpc.WithDefaultCallOptions`: ```go - myclient := grpc.Dial(ctx, target, grpc.WithDefaultCallOptions(grpc.UseCompressor("gzip"))) + myclient := grpc.NewClient(target, grpc.WithDefaultCallOptions(grpc.UseCompressor("gzip"))) ``` When specified in either of these ways, messages will be compressed using this diff --git a/Documentation/grpc-auth-support.md b/Documentation/grpc-auth-support.md index cedcaa6fa026..c8c2a556c63e 100644 --- a/Documentation/grpc-auth-support.md +++ b/Documentation/grpc-auth-support.md @@ -5,7 +5,7 @@ As outlined in the [gRPC authentication guide](https://grpc.io/docs/guides/auth. # Enabling TLS on a gRPC client ```Go -conn, err := grpc.Dial(serverAddr, grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, ""))) +conn, err := grpc.NewClient(serverAddr, grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, ""))) ``` # Enabling TLS on a gRPC server @@ -63,7 +63,7 @@ to prevent any insecure transmission of tokens. ## Google Compute Engine (GCE) ```Go -conn, err := grpc.Dial(serverAddr, grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, "")), grpc.WithPerRPCCredentials(oauth.NewComputeEngine())) +conn, err := grpc.NewClient(serverAddr, grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, "")), grpc.WithPerRPCCredentials(oauth.NewComputeEngine())) ``` ## JWT @@ -73,6 +73,6 @@ jwtCreds, err := oauth.NewServiceAccountFromFile(*serviceAccountKeyFile, *oauthS if err != nil { log.Fatalf("Failed to create JWT credentials: %v", err) } -conn, err := grpc.Dial(serverAddr, grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, "")), grpc.WithPerRPCCredentials(jwtCreds)) +conn, err := grpc.NewClient(serverAddr, grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, "")), grpc.WithPerRPCCredentials(jwtCreds)) ``` diff --git a/balancer/endpointsharding/endpointsharding_test.go b/balancer/endpointsharding/endpointsharding_test.go index ebad977e536c..5567b4c9038b 100644 --- a/balancer/endpointsharding/endpointsharding_test.go +++ b/balancer/endpointsharding/endpointsharding_test.go @@ -23,7 +23,6 @@ import ( "encoding/json" "errors" "fmt" - "log" "strings" "testing" "time" @@ -166,7 +165,7 @@ func (s) TestEndpointShardingBasic(t *testing.T) { } cc, err := grpc.NewClient(mr.Scheme()+":///", dOpts...) if err != nil { - log.Fatalf("Failed to create new client: %v", err) + t.Fatalf("Failed to create new client: %v", err) } defer cc.Close() ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) @@ -246,7 +245,7 @@ func (s) TestEndpointShardingReconnectDisabled(t *testing.T) { cc, err := grpc.NewClient(mr.Scheme()+":///", grpc.WithResolvers(mr), grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { - log.Fatalf("Failed to create new client: %v", err) + t.Fatalf("Failed to create new client: %v", err) } defer cc.Close() ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) diff --git a/credentials/insecure/insecure.go b/credentials/insecure/insecure.go index 4c805c64462c..49895e00feb6 100644 --- a/credentials/insecure/insecure.go +++ b/credentials/insecure/insecure.go @@ -30,7 +30,7 @@ import ( // NewCredentials returns a credentials which disables transport security. // // Note that using this credentials with per-RPC credentials which require -// transport security is incompatible and will cause grpc.Dial() to fail. +// transport security is incompatible and will cause grpc.NewClient() to fail. func NewCredentials() credentials.TransportCredentials { return insecureTC{} } diff --git a/dialoptions.go b/dialoptions.go index 405a2ffeb39e..57ee6f0140c0 100644 --- a/dialoptions.go +++ b/dialoptions.go @@ -360,7 +360,7 @@ func WithReturnConnectionError() DialOption { // // Note that using this DialOption with per-RPC credentials (through // WithCredentialsBundle or WithPerRPCCredentials) which require transport -// security is incompatible and will cause grpc.Dial() to fail. +// security is incompatible and will cause grpc.NewClient() to fail. // // Deprecated: use WithTransportCredentials and insecure.NewCredentials() // instead. Will be supported throughout 1.x. diff --git a/internal/stats/metrics_recorder_list_test.go b/internal/stats/metrics_recorder_list_test.go index fef3d1dff1e0..38f9472f926a 100644 --- a/internal/stats/metrics_recorder_list_test.go +++ b/internal/stats/metrics_recorder_list_test.go @@ -23,7 +23,6 @@ package stats_test import ( "context" "fmt" - "log" "strings" "testing" "time" @@ -154,7 +153,7 @@ func (s) TestMetricsRecorderList(t *testing.T) { cc, err := grpc.NewClient(mr.Scheme()+":///", grpc.WithResolvers(mr), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithStatsHandler(mr2)) if err != nil { - log.Fatalf("Failed to dial: %v", err) + t.Fatalf("grpc.NewClient() failed: %v", err) } defer cc.Close() diff --git a/stats/stats_test.go b/stats/stats_test.go index ec5ffa042f47..2e538c3d95cf 100644 --- a/stats/stats_test.go +++ b/stats/stats_test.go @@ -30,6 +30,7 @@ import ( "github.com/google/go-cmp/cmp" "google.golang.org/grpc" + "google.golang.org/grpc/connectivity" "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/internal" "google.golang.org/grpc/internal/grpctest" @@ -274,7 +275,6 @@ func (te *test) clientConn() *grpc.ClientConn { } opts := []grpc.DialOption{ grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithBlock(), grpc.WithUserAgent("test/0.0.1"), } if te.compress == "gzip" { @@ -288,10 +288,14 @@ func (te *test) clientConn() *grpc.ClientConn { } var err error - te.cc, err = grpc.Dial(te.srvAddr, opts...) + te.cc, err = grpc.NewClient(te.srvAddr, opts...) if err != nil { - te.t.Fatalf("Dial(%q) = %v", te.srvAddr, err) + te.t.Fatalf("grpc.NewClient() failed(%q) = %v", te.srvAddr, err) } + te.cc.Connect() + ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) + defer cancel() + testutils.AwaitState(ctx, te.t, te.cc, connectivity.Ready) return te.cc } diff --git a/test/channelz_test.go b/test/channelz_test.go index 0a9b88bddcc7..93847126dbe4 100644 --- a/test/channelz_test.go +++ b/test/channelz_test.go @@ -304,11 +304,11 @@ func (s) TestCZTopChannelRegistrationAndDeletion(t *testing.T) { } } -func (s) TestCZTopChannelRegistrationAndDeletionWhenDialFail(t *testing.T) { - // Make dial fails (due to no transport security specified) +func (s) TestCZTopChannelRegistrationAndDeletionWhenNewClientFail(t *testing.T) { + // Make newclient fails (due to no transport security specified) _, err := grpc.NewClient("fake.addr") if err == nil { - t.Fatal("expecting dial to fail") + t.Fatal("expecting newclient to fail") } if tcs, end := channelz.GetTopChannels(0, 0); tcs != nil || !end { t.Fatalf("GetTopChannels(0, 0) = %v, %v, want , true", tcs, end) diff --git a/test/end2end_test.go b/test/end2end_test.go index 906546ef7610..5778827a3afa 100644 --- a/test/end2end_test.go +++ b/test/end2end_test.go @@ -853,10 +853,11 @@ func (te *test) clientConn(opts ...grpc.DialOption) *grpc.ClientConn { var scheme string opts, scheme = te.configDial(opts...) var err error - te.cc, err = grpc.Dial(scheme+te.srvAddr, opts...) + te.cc, err = grpc.NewClient(scheme+te.srvAddr, opts...) if err != nil { - te.t.Fatalf("Dial(%q) = %v", scheme+te.srvAddr, err) + te.t.Fatalf("grpc.NewClient() failed(%q) = %v", scheme+te.srvAddr, err) } + te.cc.Connect() return te.cc }