Update docs and examples and tests to use NewClient instead of Dial (#7068)

Co-authored-by: Arvind Bright <arvind.bright100@gmail.com>
Co-authored-by: Doug Fawley <dfawley@google.com>
This commit is contained in:
Elisha Silas 2024-04-19 20:55:23 +03:00 committed by GitHub
parent 9cf408ec48
commit 09e6fddbcd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
78 changed files with 272 additions and 302 deletions

View File

@ -1,103 +1,97 @@
## Anti-Patterns
## Anti-Patterns of Client creation
### Dialing in gRPC
[`grpc.Dial`](https://pkg.go.dev/google.golang.org/grpc#Dial) is a function in
the gRPC library that creates a virtual connection from the gRPC client to the
gRPC server. It takes a target URI (which can represent the name of a logical
backend service and could resolve to multiple actual addresses) and a list of
options, and returns a
### How to properly create a `ClientConn`: `grpc.NewClient`
[`grpc.NewClient`](https://pkg.go.dev/google.golang.org/grpc#NewClient) is the
function in the gRPC library that creates a virtual connection from a client
application to a gRPC server. It takes a target URI (which represents the name
of a logical backend service and resolves to one or more physical addresses) and
a list of options, and returns a
[`ClientConn`](https://pkg.go.dev/google.golang.org/grpc#ClientConn) object that
represents the connection to the server. The `ClientConn` contains one or more
actual connections to real server backends and attempts to keep these
connections healthy by automatically reconnecting to them when they break.
represents the virtual connection to the server. The `ClientConn` contains one
or more actual connections to real servers and attempts to maintain these
connections by automatically reconnecting to them when they break. `NewClient`
was introduced in gRPC-Go v1.63.
The `Dial` function can also be configured with various options to customize the
behavior of the client connection. For example, developers could use options
such a
[`WithTransportCredentials`](https://pkg.go.dev/google.golang.org/grpc#WithTransportCredentials)
to configure the transport credentials to use.
### The wrong way: `grpc.Dial`
While `Dial` is commonly referred to as a "dialing" function, it doesn't
actually perform the low-level network dialing operation like
[`net.Dial`](https://pkg.go.dev/net#Dial) would. Instead, it creates a virtual
connection from the gRPC client to the gRPC server.
[`grpc.Dial`](https://pkg.go.dev/google.golang.org/grpc#Dial) is a deprecated
function that also creates the same virtual connection pool as `grpc.NewClient`.
However, unlike `grpc.NewClient`, it immediately starts connecting and supports
a few additional `DialOption`s that control this initial connection attempt.
These are: `WithBlock`, `WithTimeout`, `WithReturnConnectionError`, and
`FailOnNonTempDialError.
`Dial` does initiate the process of connecting to the server, but it uses the
ClientConn object to manage and maintain that connection over time. This is why
errors encountered during the initial connection are no different from those
that occur later on, and why it's important to handle errors from RPCs rather
than relying on options like
[`FailOnNonTempDialError`](https://pkg.go.dev/google.golang.org/grpc#FailOnNonTempDialError),
[`WithBlock`](https://pkg.go.dev/google.golang.org/grpc#WithBlock), and
[`WithReturnConnectionError`](https://pkg.go.dev/google.golang.org/grpc#WithReturnConnectionError).
In fact, `Dial` does not always establish a connection to servers by default.
The connection behavior is determined by the load balancing policy being used.
For instance, an "active" load balancing policy such as Round Robin attempts to
maintain a constant connection, while the default "pick first" policy delays
connection until an RPC is executed. Instead of using the WithBlock option, which
may not be recommended in some cases, you can call the
[`ClientConn.Connect`](https://pkg.go.dev/google.golang.org/grpc#ClientConn.Connect)
method to explicitly initiate a connection.
That `grpc.Dial` creates connections immediately is not a problem in and of
itself, but this behavior differs from how gRPC works in all other languages,
and it can be convenient to have a constructor that does not perform I/O. It
can also be confusing to users, as most people expect a function called `Dial`
to create _a_ connection which may need to be recreated if it is lost.
### Using `FailOnNonTempDialError`, `WithBlock`, and `WithReturnConnectionError`
`grpc.Dial` uses "passthrough" as the default name resolver for backward
compatibility while `grpc.NewClient` uses "dns" as its default name resolver.
This subtle diffrence is important to legacy systems that also specified a
custom dialer and expected it to receive the target string directly.
The gRPC API provides several options that can be used to configure the behavior
of dialing and connecting to a gRPC server. Some of these options, such as
`FailOnNonTempDialError`, `WithBlock`, and `WithReturnConnectionError`, rely on
failures at dial time. However, we strongly discourage developers from using
these options, as they can introduce race conditions and result in unreliable
and difficult-to-debug code.
For these reasons, using `grpc.Dial` is discouraged. Even though it is marked
as deprecated, we will continue to support it until a v2 is released (and no
plans for a v2 exist at the time this was written).
One of the most important reasons for avoiding these options, which is often
overlooked, is that connections can fail at any point in time. This means that
you need to handle RPC failures caused by connection issues, regardless of
whether a connection was never established in the first place, or if it was
created and then immediately lost. Implementing proper error handling for RPCs
is crucial for maintaining the reliability and stability of your gRPC
communication.
### Especially bad: using deprecated `DialOptions`
### Why we discourage using `FailOnNonTempDialError`, `WithBlock`, and `WithReturnConnectionError`
`FailOnNonTempDialError`, `WithBlock`, and `WithReturnConnectionError` are three
`DialOption`s that are only supported by `Dial` because they only affect the
behavior of `Dial` itself. `WithBlock` causes `Dial` to wait until the
`ClientConn` reports its `State` as `connectivity.Connected`. The other two deal
with returning connection errors before the timeout (`WithTimeout` or on the
context when using `DialContext`).
When a client attempts to connect to a gRPC server, it can encounter a variety
of errors, including network connectivity issues, server-side errors, and
incorrect usage of the gRPC API. The options `FailOnNonTempDialError`,
`WithBlock`, and `WithReturnConnectionError` are designed to handle some of
these errors, but they do so by relying on failures at dial time. This means
that they may not provide reliable or accurate information about the status of
the connection.
The reason these options can be a problem is that connections with a
`ClientConn` are dynamic -- they may come and go over time. If your client
successfully connects, the server could go down 1 second later, and your RPCs
will fail. "Knowing you are connected" does not tell you much in this regard.
For example, if a client uses `WithBlock` to wait for a connection to be
established, it may end up waiting indefinitely if the server is not responding.
Similarly, if a client uses `WithReturnConnectionError` to return a connection
error if dialing fails, it may miss opportunities to recover from transient
network issues that are resolved shortly after the initial dial attempt.
Additionally, _all_ RPCs created on an "idle" or a "connecting" `ClientConn`
will wait until their deadline or until a connection is established before
failing. This means that you don't need to check that a `ClientConn` is "ready"
before starting your RPCs. By default, RPCs will fail if the `ClientConn`
enters the "transient failure" state, but setting `WaitForReady(true)` on a
call will cause it to queue even in the "transient failure" state, and it will
only ever fail due to a deadline, a server response, or a connection loss after
the RPC was sent to a server.
Some users of `Dial` use it as a way to validate the configuration of their
system. If you wish to maintain this behavior but migrate to `NewClient`, you
can call `State` and `WaitForStateChange` until the channel is connected.
However, if this fails, it does not mean that your configuration was bad - it
could also mean the service is not reachable by the client due to connectivity
reasons.
## Best practices for error handling in gRPC
Instead of relying on failures at dial time, we strongly encourage developers to
rely on errors from RPCs. When a client makes an RPC, it can receive an error
response from the server. These errors can provide valuable information about
rely on errors from RPCs. When a client makes an RPC, it can receive an error
response from the server. These errors can provide valuable information about
what went wrong, including information about network issues, server-side errors,
and incorrect usage of the gRPC API.
By handling errors from RPCs correctly, developers can write more reliable and
robust gRPC applications. Here are some best practices for error handling in
robust gRPC applications. Here are some best practices for error handling in
gRPC:
- Always check for error responses from RPCs and handle them appropriately.
- Use the `status` field of the error response to determine the type of error that
occurred.
- Always check for error responses from RPCs and handle them appropriately.
- Use the `status` field of the error response to determine the type of error
that occurred.
- When retrying failed RPCs, consider using the built-in retry mechanism
provided by gRPC-Go, if available, instead of manually implementing retries.
Refer to the [gRPC-Go retry example
documentation](https://github.com/grpc/grpc-go/blob/master/examples/features/retry/README.md)
for more information.
- Avoid using `FailOnNonTempDialError`, `WithBlock`, and
`WithReturnConnectionError`, as these options can introduce race conditions and
result in unreliable and difficult-to-debug code.
- If making the outgoing RPC in order to handle an incoming RPC, be sure to
translate the status code before returning the error from your method handler.
For example, if the error is an `INVALID_ARGUMENT` error, that probably means
for more information. Note that this is not a substitute for client-side
retries as errors that occur after an RPC starts on a server cannot be
retried through gRPC's built-in mechanism.
- If making an outgoing RPC from a server handler, be sure to translate the
status code before returning the error from your method handler. For example,
if the error is an `INVALID_ARGUMENT` status code, that probably means
your service has a bug (otherwise it shouldn't have triggered this error), in
which case `INTERNAL` is more appropriate to return back to your users.
@ -106,7 +100,7 @@ gRPC:
The following code snippet demonstrates how to handle errors from an RPC in
gRPC:
```go
```go
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
@ -118,89 +112,72 @@ if err != nil {
return nil, err
}
// Use the response as appropriate
// Use the response as appropriate
log.Printf("MyRPC response: %v", res)
```
To determine the type of error that occurred, you can use the status field of
the error response:
```go
resp, err := client.MakeRPC(context.Background(), request)
resp, err := client.MakeRPC(context.TODO(), request)
if err != nil {
status, ok := status.FromError(err)
if ok {
// Handle the error based on its status code
if status, ok := status.FromError(err); ok {
// Handle the error based on its status code
if status.Code() == codes.NotFound {
log.Println("Requested resource not found")
} else {
log.Printf("RPC error: %v", status.Message())
}
} else {
//Handle non-RPC errors
// Handle non-RPC errors
log.Printf("Non-RPC error: %v", err)
}
return
}
}
// Use the response as needed
log.Printf("Response received: %v", resp)
// Use the response as needed
log.Printf("Response received: %v", resp)
```
### Example: Using a backoff strategy
When retrying failed RPCs, use a backoff strategy to avoid overwhelming the
server or exacerbating network issues:
```go
```go
var res *MyResponse
var err error
// If the user doesn't have a context with a deadline, create one
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
retryableStatusCodes := map[codes.Code]bool{
codes.Unavailable: true, // etc
}
// Retry the RPC call a maximum number of times
// Retry the RPC a maximum number of times.
for i := 0; i < maxRetries; i++ {
// Make the RPC call
res, err = client.MyRPC(ctx, &MyRequest{})
// Check if the RPC call was successful
if err == nil {
// The RPC was successful, so break out of the loop
// Make the RPC.
res, err = client.MyRPC(context.TODO(), &MyRequest{})
// Check if the RPC was successful.
if !retryableStatusCodes[status.Code(err)] {
// The RPC was successful or errored in a non-retryable way;
// do not retry.
break
}
// The RPC failed, so wait for a backoff period before retrying
backoff := time.Duration(i) * time.Second
// The RPC is retryable; wait for a backoff period before retrying.
backoff := time.Duration(i+1) * time.Second
log.Printf("Error calling MyRPC: %v; retrying in %v", err, backoff)
time.Sleep(backoff)
}
// Check if the RPC call was successful after all retries
// Check if the RPC was successful after all retries.
if err != nil {
// All retries failed, so handle the error appropriately
log.Printf("Error calling MyRPC: %v", err)
return nil, err
}
// Use the response as appropriate
// Use the response as appropriate.
log.Printf("MyRPC response: %v", res)
```
## Conclusion
The
[`FailOnNonTempDialError`](https://pkg.go.dev/google.golang.org/grpc#FailOnNonTempDialError),
[`WithBlock`](https://pkg.go.dev/google.golang.org/grpc#WithBlock), and
[`WithReturnConnectionError`](https://pkg.go.dev/google.golang.org/grpc#WithReturnConnectionError)
options are designed to handle errors at dial time, but they can introduce race
conditions and result in unreliable and difficult-to-debug code. Instead of
relying on these options, we strongly encourage developers to rely on errors
from RPCs for error handling. By following best practices for error handling in
gRPC, developers can write more reliable and robust gRPC applications.

View File

@ -279,9 +279,9 @@ func (s) TestAuditLogger(t *testing.T) {
go s.Serve(lis)
// Setup gRPC test client with certificates containing a SPIFFE Id.
clientConn, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(clientCreds))
clientConn, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(clientCreds))
if err != nil {
t.Fatalf("grpc.Dial(%v) failed: %v", lis.Addr().String(), err)
t.Fatalf("grpc.NewClient(%v) failed: %v", lis.Addr().String(), err)
}
defer clientConn.Close()
client := testgrpc.NewTestServiceClient(clientConn)

View File

@ -326,9 +326,9 @@ func (s) TestStaticPolicyEnd2End(t *testing.T) {
go s.Serve(lis)
// Establish a connection to the server.
clientConn, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
clientConn, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("grpc.Dial(%v) failed: %v", lis.Addr().String(), err)
t.Fatalf("grpc.NewClient(%v) failed: %v", lis.Addr().String(), err)
}
defer clientConn.Close()
client := testgrpc.NewTestServiceClient(clientConn)
@ -400,9 +400,9 @@ func (s) TestAllowsRPCRequestWithPrincipalsFieldOnTLSAuthenticatedConnection(t *
if err != nil {
t.Fatalf("failed to load credentials: %v", err)
}
clientConn, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(creds))
clientConn, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(creds))
if err != nil {
t.Fatalf("grpc.Dial(%v) failed: %v", lis.Addr().String(), err)
t.Fatalf("grpc.NewClient(%v) failed: %v", lis.Addr().String(), err)
}
defer clientConn.Close()
client := testgrpc.NewTestServiceClient(clientConn)
@ -478,9 +478,9 @@ func (s) TestAllowsRPCRequestWithPrincipalsFieldOnMTLSAuthenticatedConnection(t
RootCAs: roots,
ServerName: "x.test.example.com",
})
clientConn, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(creds))
clientConn, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(creds))
if err != nil {
t.Fatalf("grpc.Dial(%v) failed: %v", lis.Addr().String(), err)
t.Fatalf("grpc.NewClient(%v) failed: %v", lis.Addr().String(), err)
}
defer clientConn.Close()
client := testgrpc.NewTestServiceClient(clientConn)
@ -516,9 +516,9 @@ func (s) TestFileWatcherEnd2End(t *testing.T) {
go s.Serve(lis)
// Establish a connection to the server.
clientConn, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
clientConn, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("grpc.Dial(%v) failed: %v", lis.Addr().String(), err)
t.Fatalf("grpc.NewClient(%v) failed: %v", lis.Addr().String(), err)
}
defer clientConn.Close()
client := testgrpc.NewTestServiceClient(clientConn)
@ -585,9 +585,9 @@ func (s) TestFileWatcher_ValidPolicyRefresh(t *testing.T) {
go s.Serve(lis)
// Establish a connection to the server.
clientConn, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
clientConn, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("grpc.Dial(%v) failed: %v", lis.Addr().String(), err)
t.Fatalf("grpc.NewClient(%v) failed: %v", lis.Addr().String(), err)
}
defer clientConn.Close()
client := testgrpc.NewTestServiceClient(clientConn)
@ -633,9 +633,9 @@ func (s) TestFileWatcher_InvalidPolicySkipReload(t *testing.T) {
go s.Serve(lis)
// Establish a connection to the server.
clientConn, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
clientConn, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("grpc.Dial(%v) failed: %v", lis.Addr().String(), err)
t.Fatalf("grpc.NewClient(%v) failed: %v", lis.Addr().String(), err)
}
defer clientConn.Close()
client := testgrpc.NewTestServiceClient(clientConn)
@ -684,9 +684,9 @@ func (s) TestFileWatcher_RecoversFromReloadFailure(t *testing.T) {
go s.Serve(lis)
// Establish a connection to the server.
clientConn, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
clientConn, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("grpc.Dial(%v) failed: %v", lis.Addr().String(), err)
t.Fatalf("grpc.NewClient(%v) failed: %v", lis.Addr().String(), err)
}
defer clientConn.Close()
client := testgrpc.NewTestServiceClient(clientConn)

View File

@ -458,7 +458,7 @@ func (s) TestGRPCLB_Basic(t *testing.T) {
grpc.WithContextDialer(fakeNameDialer),
grpc.WithUserAgent(testUserAgent),
}
cc, err := grpc.Dial(r.Scheme()+":///"+beServerName, dopts...)
cc, err := grpc.NewClient(r.Scheme()+":///"+beServerName, dopts...)
if err != nil {
t.Fatalf("Failed to dial to the backend %v", err)
}
@ -515,7 +515,7 @@ func (s) TestGRPCLB_Weighted(t *testing.T) {
grpc.WithTransportCredentials(&serverNameCheckCreds{}),
grpc.WithContextDialer(fakeNameDialer),
}
cc, err := grpc.Dial(r.Scheme()+":///"+beServerName, dopts...)
cc, err := grpc.NewClient(r.Scheme()+":///"+beServerName, dopts...)
if err != nil {
t.Fatalf("Failed to dial to the backend %v", err)
}
@ -595,7 +595,7 @@ func (s) TestGRPCLB_DropRequest(t *testing.T) {
grpc.WithTransportCredentials(&serverNameCheckCreds{}),
grpc.WithContextDialer(fakeNameDialer),
}
cc, err := grpc.Dial(r.Scheme()+":///"+beServerName, dopts...)
cc, err := grpc.NewClient(r.Scheme()+":///"+beServerName, dopts...)
if err != nil {
t.Fatalf("Failed to dial to the backend %v", err)
}
@ -767,7 +767,7 @@ func (s) TestGRPCLB_BalancerDisconnects(t *testing.T) {
grpc.WithTransportCredentials(&serverNameCheckCreds{}),
grpc.WithContextDialer(fakeNameDialer),
}
cc, err := grpc.Dial(r.Scheme()+":///"+beServerName, dopts...)
cc, err := grpc.NewClient(r.Scheme()+":///"+beServerName, dopts...)
if err != nil {
t.Fatalf("Failed to dial to the backend %v", err)
}
@ -938,7 +938,7 @@ func (s) TestGRPCLB_ExplicitFallback(t *testing.T) {
grpc.WithTransportCredentials(&serverNameCheckCreds{}),
grpc.WithContextDialer(fakeNameDialer),
}
cc, err := grpc.Dial(r.Scheme()+":///"+beServerName, dopts...)
cc, err := grpc.NewClient(r.Scheme()+":///"+beServerName, dopts...)
if err != nil {
t.Fatalf("Failed to dial to the backend %v", err)
}

View File

@ -232,9 +232,9 @@ func (s) TestLeastRequestE2E(t *testing.T) {
ServiceConfig: sc,
})
cc, err := grpc.Dial(mr.Scheme()+":///", grpc.WithResolvers(mr), grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(mr.Scheme()+":///", grpc.WithResolvers(mr), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("grpc.Dial() failed: %v", err)
t.Fatalf("grpc.NewClient() failed: %v", err)
}
defer cc.Close()
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
@ -347,9 +347,9 @@ func (s) TestLeastRequestPersistsCounts(t *testing.T) {
ServiceConfig: sc,
})
cc, err := grpc.Dial(mr.Scheme()+":///", grpc.WithResolvers(mr), grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(mr.Scheme()+":///", grpc.WithResolvers(mr), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("grpc.Dial() failed: %v", err)
t.Fatalf("grpc.NewClient() failed: %v", err)
}
defer cc.Close()
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
@ -488,9 +488,9 @@ func (s) TestConcurrentRPCs(t *testing.T) {
ServiceConfig: sc,
})
cc, err := grpc.Dial(mr.Scheme()+":///", grpc.WithResolvers(mr), grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(mr.Scheme()+":///", grpc.WithResolvers(mr), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("grpc.Dial() failed: %v", err)
t.Fatalf("grpc.NewClient() failed: %v", err)
}
defer cc.Close()
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)

View File

@ -316,7 +316,7 @@ func (te *test) clientConn() *grpc.ClientConn {
opts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()}
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)
}

View File

@ -128,8 +128,8 @@ func (s) TestClientConnAuthority_CredsAndDialOptionMismatch(t *testing.T) {
t.Fatalf("credentials.NewClientTLSFromFile(_, %q) failed: %v", err, serverNameOverride)
}
opts := []DialOption{WithTransportCredentials(creds), WithAuthority("authority-override")}
if cc, err := Dial("Non-Existent.Server:8000", opts...); err == nil {
if cc, err := NewClient("Non-Existent.Server:8000", opts...); err == nil {
cc.Close()
t.Fatal("grpc.Dial() succeeded when expected to fail")
t.Fatal("grpc.NewClient() succeeded when expected to fail")
}
}

View File

@ -385,9 +385,9 @@ func versions(minMajor, minMinor, maxMajor, maxMinor uint32) *altspb.RpcProtocol
func establishAltsConnection(t *testing.T, handshakerAddress, serverAddress string) {
clientCreds := NewClientCreds(&ClientOptions{HandshakerServiceAddress: handshakerAddress})
conn, err := grpc.Dial(serverAddress, grpc.WithTransportCredentials(clientCreds))
conn, err := grpc.NewClient(serverAddress, grpc.WithTransportCredentials(clientCreds))
if err != nil {
t.Fatalf("grpc.Dial(%v) failed: %v", serverAddress, err)
t.Fatalf("grpc.NewClient(%v) failed: %v", serverAddress, err)
}
defer conn.Close()
ctx, cancel := context.WithTimeout(context.Background(), defaultTestLongTimeout)

View File

@ -103,9 +103,9 @@ func (s) TestTLS_MinVersion12(t *testing.T) {
}
defer ss.Stop()
cc, err := grpc.Dial(ss.Address, grpc.WithTransportCredentials(clientCreds))
cc, err := grpc.NewClient(ss.Address, grpc.WithTransportCredentials(clientCreds))
if err != nil {
t.Fatalf("grpc.Dial error: %v", err)
t.Fatalf("grpc.NewClient error: %v", err)
}
defer cc.Close()
@ -189,9 +189,9 @@ func (s) TestTLS_CipherSuites(t *testing.T) {
}
defer ss.Stop()
cc, err := grpc.Dial("dns:"+ss.Address, grpc.WithTransportCredentials(clientCreds))
cc, err := grpc.NewClient("dns:"+ss.Address, grpc.WithTransportCredentials(clientCreds))
if err != nil {
t.Fatalf("grpc.Dial error: %v", err)
t.Fatalf("grpc.NewClient error: %v", err)
}
defer cc.Close()

View File

@ -122,7 +122,7 @@ func (s) TestEncodeDoesntPanicOnServer(t *testing.T) {
defer backend.Stop()
// Create a channel to the above server.
cc, err := grpc.Dial(backend.Address, grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(backend.Address, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("Failed to dial test backend at %q: %v", backend.Address, err)
}
@ -159,7 +159,7 @@ func (s) TestDecodeDoesntPanicOnServer(t *testing.T) {
// Create a channel to the above server. Since we do not specify any codec
// here, the proto codec will get automatically used.
cc, err := grpc.Dial(backend.Address, grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(backend.Address, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("Failed to dial test backend at %q: %v", backend.Address, err)
}
@ -196,7 +196,7 @@ func (s) TestEncodeDoesntPanicOnClient(t *testing.T) {
ec := &errProtoCodec{name: t.Name(), encodingErr: encodingErr}
// Create a channel to the above server.
cc, err := grpc.Dial(backend.Address, grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(backend.Address, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("Failed to dial test backend at %q: %v", backend.Address, err)
}
@ -232,7 +232,7 @@ func (s) TestDecodeDoesntPanicOnClient(t *testing.T) {
ec := &errProtoCodec{name: t.Name(), decodingErr: decodingErr}
// Create a channel to the above server.
cc, err := grpc.Dial(backend.Address, grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(backend.Address, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("Failed to dial test backend at %q: %v", backend.Address, err)
}
@ -288,7 +288,7 @@ func (s) TestForceServerCodec(t *testing.T) {
defer backend.Stop()
// Create a channel to the above server.
cc, err := grpc.Dial(backend.Address, grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(backend.Address, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("Failed to dial test backend at %q: %v", backend.Address, err)
}

View File

@ -66,7 +66,7 @@ func main() {
grpc.WithTransportCredentials(creds),
}
conn, err := grpc.Dial(*addr, opts...)
conn, err := grpc.NewClient(*addr, opts...)
if err != nil {
log.Fatalf("did not connect: %v", err)
}

View File

@ -99,9 +99,9 @@ func main() {
log.Fatalf("failed to load credentials: %v", err)
}
// Set up a connection to the server.
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(creds))
conn, err := grpc.NewClient(*addr, grpc.WithTransportCredentials(creds))
if err != nil {
log.Fatalf("grpc.Dial(%q): %v", *addr, err)
log.Fatalf("grpc.NewClient(%q): %v", *addr, err)
}
defer conn.Close()

View File

@ -56,7 +56,7 @@ func main() {
flag.Parse()
// Set up a connection to the server.
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("did not connect: %v", err)
}

View File

@ -38,7 +38,7 @@ func main() {
flag.Parse()
// Set up a connection to the server.
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("did not connect: %v", err)
}

View File

@ -73,7 +73,7 @@ func streamingCall(c pb.EchoClient, requestID int, message string, want codes.Co
func main() {
flag.Parse()
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("did not connect: %v", err)
}

View File

@ -95,7 +95,7 @@ func (s *server) Close() {
func newEchoServer() *server {
target := fmt.Sprintf("localhost:%v", *port)
cc, err := grpc.Dial(target, grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(target, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("did not connect: %v", err)
}

View File

@ -60,7 +60,7 @@ func main() {
/***** Initialize manual resolver and Dial *****/
r := manual.NewBuilderWithScheme("whatever")
// Set up a connection to the server.
conn, err := grpc.Dial(r.Scheme()+":///test.server", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r), grpc.WithDefaultServiceConfig(`{"loadBalancingPolicy":"round_robin"}`))
conn, err := grpc.NewClient(r.Scheme()+":///test.server", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r), grpc.WithDefaultServiceConfig(`{"loadBalancingPolicy":"round_robin"}`))
if err != nil {
log.Fatalf("did not connect: %v", err)
}

View File

@ -50,7 +50,7 @@ func main() {
altsTC := alts.NewClientCreds(alts.DefaultClientOptions())
// Set up a connection to the server.
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(altsTC))
conn, err := grpc.NewClient(*addr, grpc.WithTransportCredentials(altsTC))
if err != nil {
log.Fatalf("did not connect: %v", err)
}

View File

@ -54,7 +54,7 @@ func main() {
}
// Set up a connection to the server.
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(creds))
conn, err := grpc.NewClient(*addr, grpc.WithTransportCredentials(creds))
if err != nil {
log.Fatalf("did not connect: %v", err)
}

View File

@ -71,7 +71,7 @@ func main() {
RootCAs: ca,
}
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig)))
conn, err := grpc.NewClient(*addr, grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig)))
if err != nil {
log.Fatalf("did not connect: %v", err)
}

View File

@ -39,7 +39,7 @@ func main() {
flag.Parse()
// Set up a connection to the server.
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("did not connect: %v", err)
}

View File

@ -44,7 +44,7 @@ func main() {
}
// Set up a connection to the server.
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("Failed to connect: %v", err)
}

View File

@ -41,7 +41,7 @@ func main() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("did not connect: %v", err)
}

View File

@ -72,9 +72,9 @@ func main() {
grpc.WithDefaultServiceConfig(serviceConfig),
}
conn, err := grpc.Dial(address, options...)
conn, err := grpc.NewClient(address, options...)
if err != nil {
log.Fatalf("grpc.Dial(%q): %v", address, err)
log.Fatalf("grpc.NewClient(%q): %v", address, err)
}
defer conn.Close()

View File

@ -153,7 +153,7 @@ func main() {
}
// Set up a connection to the server.
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(creds), grpc.WithUnaryInterceptor(unaryInterceptor), grpc.WithStreamInterceptor(streamInterceptor))
conn, err := grpc.NewClient(*addr, grpc.WithTransportCredentials(creds), grpc.WithUnaryInterceptor(unaryInterceptor), grpc.WithStreamInterceptor(streamInterceptor))
if err != nil {
log.Fatalf("did not connect: %v", err)
}

View File

@ -43,7 +43,7 @@ var kacp = keepalive.ClientParameters{
func main() {
flag.Parse()
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithKeepaliveParams(kacp))
conn, err := grpc.NewClient(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithKeepaliveParams(kacp))
if err != nil {
log.Fatalf("did not connect: %v", err)
}

View File

@ -57,7 +57,7 @@ func makeRPCs(cc *grpc.ClientConn, n int) {
func main() {
// "pick_first" is the default, so there's no need to set the load balancing policy.
pickfirstConn, err := grpc.Dial(
pickfirstConn, err := grpc.NewClient(
fmt.Sprintf("%s:///%s", exampleScheme, exampleServiceName),
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
@ -72,7 +72,7 @@ func main() {
fmt.Println()
// Make another ClientConn with round_robin policy.
roundrobinConn, err := grpc.Dial(
roundrobinConn, err := grpc.NewClient(
fmt.Sprintf("%s:///%s", exampleScheme, exampleServiceName),
grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"round_robin":{}}]}`), // This sets the initial balancing policy.
grpc.WithTransportCredentials(insecure.NewCredentials()),

View File

@ -287,7 +287,7 @@ const message = "this is examples/metadata"
func main() {
flag.Parse()
// Set up a connection to the server.
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("did not connect: %v", err)
}

View File

@ -69,9 +69,9 @@ func callBidiStreamingEcho(ctx context.Context, client pb.EchoClient) {
func main() {
flag.Parse()
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("grpc.Dial(%q): %v", *addr, err)
log.Fatalf("grpc.NewClient(%q): %v", *addr, err)
}
defer conn.Close()

View File

@ -59,7 +59,7 @@ func callUnaryEcho(client ecpb.EchoClient, message string) {
func main() {
flag.Parse()
// Set up a connection to the server.
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("did not connect: %v", err)
}

View File

@ -56,7 +56,7 @@ func makeRPCs(cc *grpc.ClientConn, n int) {
}
func main() {
passthroughConn, err := grpc.Dial(
passthroughConn, err := grpc.NewClient(
fmt.Sprintf("passthrough:///%s", backendAddr), // Dial to "passthrough:///localhost:50051"
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
@ -70,7 +70,7 @@ func main() {
fmt.Println()
exampleConn, err := grpc.Dial(
exampleConn, err := grpc.NewClient(
fmt.Sprintf("%s:///%s", exampleScheme, exampleServiceName), // Dial to "example:///resolver.example.grpc.io"
grpc.WithTransportCredentials(insecure.NewCredentials()),
)

View File

@ -44,7 +44,7 @@ func main() {
// Set up a connection to the server. Configure to use our custom LB
// policy which will receive all the ORCA load reports.
conn, err := grpc.Dial(*addr,
conn, err := grpc.NewClient(*addr,
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"orca_example":{}}]}`),
)
@ -97,14 +97,7 @@ type orcaLB struct {
}
func (o *orcaLB) UpdateClientConnState(ccs balancer.ClientConnState) error {
// We assume only one update, ever, containing exactly one address, given
// the use of the "passthrough" (default) name resolver.
addrs := ccs.ResolverState.Addresses
if len(addrs) != 1 {
return fmt.Errorf("orcaLB: expected 1 address; received: %v", addrs)
}
// Create one SubConn for the address and connect it.
var sc balancer.SubConn
sc, err := o.cc.NewSubConn(addrs, balancer.NewSubConnOptions{

View File

@ -49,7 +49,7 @@ var (
// use grpc.WithDefaultServiceConfig() to set service config
func retryDial() (*grpc.ClientConn, error) {
return grpc.Dial(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithDefaultServiceConfig(retryPolicy))
return grpc.NewClient(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithDefaultServiceConfig(retryPolicy))
}
func main() {

View File

@ -41,7 +41,7 @@ func main() {
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithStatsHandler(statshandler.New()),
}
conn, err := grpc.Dial(*addr, opts...)
conn, err := grpc.NewClient(*addr, opts...)
if err != nil {
log.Fatalf("failed to connect to server %q: %v", *addr, err)
}

View File

@ -63,9 +63,9 @@ func makeRPCs(cc *grpc.ClientConn, n int) {
func main() {
flag.Parse()
sockAddr := fmt.Sprintf("unix-abstract:%v", *addr)
cc, err := grpc.Dial(sockAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(sockAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("grpc.Dial(%q) failed: %v", sockAddr, err)
log.Fatalf("grpc.NewClient(%q) failed: %v", sockAddr, err)
}
defer cc.Close()

View File

@ -59,7 +59,7 @@ func serve() {
}
func main() {
conn, err := grpc.Dial("localhost:50053", grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient("localhost:50053", grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("did not connect: %v", err)
}

View File

@ -56,9 +56,9 @@ func main() {
log.Fatalf("failed to create client-side xDS credentials: %v", err)
}
}
conn, err := grpc.Dial(*target, grpc.WithTransportCredentials(creds))
conn, err := grpc.NewClient(*target, grpc.WithTransportCredentials(creds))
if err != nil {
log.Fatalf("grpc.Dial(%s) failed: %v", *target, err)
log.Fatalf("grpc.NewClient(%s) failed: %v", *target, err)
}
defer conn.Close()

View File

@ -488,9 +488,9 @@ func (s) TestChannelIdleness_Enabled_IdleTimeoutRacesWithRPCs(t *testing.T) {
grpc.WithIdleTimeout(defaultTestShortTimeout),
grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"round_robin":{}}]}`),
}
cc, err := grpc.Dial(r.Scheme()+":///test.server", dopts...)
cc, err := grpc.NewClient(r.Scheme()+":///test.server", dopts...)
if err != nil {
t.Fatalf("grpc.Dial() failed: %v", err)
t.Fatalf("grpc.NewClient() failed: %v", err)
}
defer cc.Close()
@ -531,9 +531,9 @@ func (s) TestChannelIdleness_Connect(t *testing.T) {
grpc.WithIdleTimeout(defaultTestShortIdleTimeout),
grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"round_robin":{}}]}`),
}
cc, err := grpc.Dial(r.Scheme()+":///test.server", dopts...)
cc, err := grpc.NewClient(r.Scheme()+":///test.server", dopts...)
if err != nil {
t.Fatalf("grpc.Dial() failed: %v", err)
t.Fatalf("grpc.NewClient() failed: %v", err)
}
defer cc.Close()
@ -581,9 +581,9 @@ func (s) TestChannelIdleness_RaceBetweenEnterAndExitIdleMode(t *testing.T) {
grpc.WithIdleTimeout(30 * time.Minute),
grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"pick_first":{}}]}`),
}
cc, err := grpc.Dial(r.Scheme()+":///test.server", dopts...)
cc, err := grpc.NewClient(r.Scheme()+":///test.server", dopts...)
if err != nil {
t.Fatalf("grpc.Dial() failed: %v", err)
t.Fatalf("grpc.NewClient() failed: %v", err)
}
defer cc.Close()

View File

@ -105,9 +105,9 @@ func (s) TestCustomLB(t *testing.T) {
ServiceConfig: sc,
})
cc, err := grpc.Dial(mr.Scheme()+":///", grpc.WithResolvers(mr), grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(mr.Scheme()+":///", grpc.WithResolvers(mr), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("grpc.Dial() failed: %v", err)
t.Fatalf("grpc.NewClient() failed: %v", err)
}
defer cc.Close()
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)

View File

@ -118,9 +118,9 @@ func (s) TestE2ECallMetricsUnary(t *testing.T) {
defer srv.Stop()
// Dial the stub server.
cc, err := grpc.Dial(srv.Address, grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(srv.Address, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("grpc.Dial(%s) failed: %v", srv.Address, err)
t.Fatalf("grpc.NewClient(%s) failed: %v", srv.Address, err)
}
defer cc.Close()
@ -239,9 +239,9 @@ func (s) TestE2ECallMetricsStreaming(t *testing.T) {
defer srv.Stop()
// Dial the stub server.
cc, err := grpc.Dial(srv.Address, grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(srv.Address, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("grpc.Dial(%s) failed: %v", srv.Address, err)
t.Fatalf("grpc.NewClient(%s) failed: %v", srv.Address, err)
}
defer cc.Close()

View File

@ -106,9 +106,9 @@ func (s) TestE2E_CustomBackendMetrics_OutOfBand(t *testing.T) {
t.Logf("Started gRPC server at %s...", lis.Addr().String())
// Dial the test server.
cc, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("grpc.Dial(%s) failed: %v", lis.Addr().String(), err)
t.Fatalf("grpc.NewClient(%s) failed: %v", lis.Addr().String(), err)
}
defer cc.Close()

View File

@ -413,7 +413,7 @@ func (x) TestReflectionEnd2end(t *testing.T) {
t.Cleanup(s.Stop)
// Create client.
conn, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("cannot connect to server: %v", err)
}

View File

@ -150,9 +150,9 @@ func (s) TestEnterIdleDuringResolverUpdateState(t *testing.T) {
}
resolver.Register(rb)
cc, err := grpc.Dial(name+":///", grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(name+":///", grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("grpc.Dial error: %v", err)
t.Fatalf("grpc.NewClient error: %v", err)
}
defer cc.Close()
@ -196,12 +196,12 @@ func (s) TestEnterIdleDuringBalancerUpdateState(t *testing.T) {
}
resolver.Register(rb)
cc, err := grpc.Dial(
cc, err := grpc.NewClient(
name+":///",
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"`+name+`":{}}]}`))
if err != nil {
t.Fatalf("grpc.Dial error: %v", err)
t.Fatalf("grpc.NewClient error: %v", err)
}
defer cc.Close()
@ -241,12 +241,12 @@ func (s) TestEnterIdleDuringBalancerNewSubConn(t *testing.T) {
}
resolver.Register(rb)
cc, err := grpc.Dial(
cc, err := grpc.NewClient(
name+":///",
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"`+name+`":{}}]}`))
if err != nil {
t.Fatalf("grpc.Dial error: %v", err)
t.Fatalf("grpc.NewClient error: %v", err)
}
defer cc.Close()

View File

@ -90,9 +90,9 @@ func main() {
}
// Make a connection using the credentials.
conn, err := grpc.Dial(address, grpc.WithTransportCredentials(clientTLSCreds))
conn, err := grpc.NewClient(address, grpc.WithTransportCredentials(clientTLSCreds))
if err != nil {
log.Fatalf("grpc.DialContext to %s failed: %v", address, err)
log.Fatalf("grpc.NewClient to %s failed: %v", address, err)
}
client := pb.NewGreeterClient(conn)

View File

@ -124,9 +124,9 @@ func (s) TestStreamWorkers_RPCsAndStop(t *testing.T) {
ccs := make([]*grpc.ClientConn, numChannels)
for i := 0; i < numChannels; i++ {
var err error
ccs[i], err = grpc.Dial(ss.Address, grpc.WithTransportCredentials(insecure.NewCredentials()))
ccs[i], err = grpc.NewClient(ss.Address, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("[iteration: %d] grpc.Dial(%s) failed: %v", i, ss.Address, err)
t.Fatalf("[iteration: %d] grpc.NewClient(%s) failed: %v", i, ss.Address, err)
}
defer ccs[i].Close()
client := testgrpc.NewTestServiceClient(ccs[i])

View File

@ -228,9 +228,9 @@ func (s) TestAuthorityReplacedWithResolverAddress(t *testing.T) {
r := manual.NewBuilderWithScheme("whatever")
r.InitialState(resolver.State{Addresses: []resolver.Address{{Addr: ss.Address, ServerName: expectedAuthority}}})
cc, err := grpc.Dial(r.Scheme()+":///whatever", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r))
cc, err := grpc.NewClient(r.Scheme()+":///whatever", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r))
if err != nil {
t.Fatalf("grpc.Dial(%q) = %v", ss.Address, err)
t.Fatalf("grpc.NewClient(%q) = %v", ss.Address, err)
}
defer cc.Close()

View File

@ -429,7 +429,7 @@ func (s) TestAddressAttributesInNewSubConn(t *testing.T) {
grpc.WithResolvers(r),
grpc.WithDefaultServiceConfig(fmt.Sprintf(`{ "loadBalancingConfig": [{"%v": {}}] }`, attrBalancerName)),
}
cc, err := grpc.Dial(r.Scheme()+":///test.server", dopts...)
cc, err := grpc.NewClient(r.Scheme()+":///test.server", dopts...)
if err != nil {
t.Fatal(err)
}
@ -753,7 +753,7 @@ func (s) TestAuthorityInBuildOptions(t *testing.T) {
grpc.WithResolvers(r),
grpc.WithDefaultServiceConfig(fmt.Sprintf(`{ "loadBalancingConfig": [{"%v": {}}] }`, balancerName)),
}, test.dopts...)
cc, err := grpc.Dial(r.Scheme()+":///"+dialTarget, dopts...)
cc, err := grpc.NewClient(r.Scheme()+":///"+dialTarget, dopts...)
if err != nil {
t.Fatal(err)
}
@ -863,9 +863,9 @@ func (s) TestMetadataInPickResult(t *testing.T) {
grpc.WithResolvers(r),
grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"loadBalancingConfig": [{"%s":{}}]}`, t.Name())),
}
cc, err := grpc.Dial(r.Scheme()+":///test.server", dopts...)
cc, err := grpc.NewClient(r.Scheme()+":///test.server", dopts...)
if err != nil {
t.Fatalf("grpc.Dial(): %v", err)
t.Fatalf("grpc.NewClient(): %v", err)
}
defer cc.Close()
tc := testgrpc.NewTestServiceClient(cc)

View File

@ -302,7 +302,7 @@ func (s) TestCZTopChannelRegistrationAndDeletion(t *testing.T) {
func (s) TestCZTopChannelRegistrationAndDeletionWhenDialFail(t *testing.T) {
// Make dial fails (due to no transport security specified)
_, err := grpc.Dial("fake.addr")
_, err := grpc.NewClient("fake.addr")
if err == nil {
t.Fatal("expecting dial to fail")
}

View File

@ -41,9 +41,9 @@ import (
// the expected error code.
func (s) TestClientConnClose_WithPendingRPC(t *testing.T) {
r := manual.NewBuilderWithScheme("whatever")
cc, err := grpc.Dial(r.Scheme()+":///test.server", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r))
cc, err := grpc.NewClient(r.Scheme()+":///test.server", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r))
if err != nil {
t.Fatalf("grpc.Dial() failed: %v", err)
t.Fatalf("grpc.NewClient() failed: %v", err)
}
client := testgrpc.NewTestServiceClient(cc)

View File

@ -73,7 +73,7 @@ func (s) TestGracefulClientOnGoAway(t *testing.T) {
}
go s.Serve(lis)
cc, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("Failed to dial server: %v", err)
}

View File

@ -242,9 +242,9 @@ func startServer(t *testing.T, headerFields ...[]string) (serverAddr string, cle
}
func doHTTPHeaderTest(lisAddr string, errCode codes.Code) error {
cc, err := grpc.Dial(lisAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(lisAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return fmt.Errorf("dial(%q): %v", lisAddr, err)
return fmt.Errorf("NewClient(%q): %v", lisAddr, err)
}
defer cc.Close()
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)

View File

@ -126,9 +126,9 @@ func (s) TestInsecureCreds(t *testing.T) {
if test.clientInsecureCreds {
opts = []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())}
}
cc, err := grpc.Dial(addr, opts...)
cc, err := grpc.NewClient(addr, opts...)
if err != nil {
t.Fatalf("grpc.Dial(%q) failed: %v", addr, err)
t.Fatalf("grpc.NewClient(%q) failed: %v", addr, err)
}
defer cc.Close()
@ -165,9 +165,9 @@ func (s) TestInsecureCreds_WithPerRPCCredentials_AsCallOption(t *testing.T) {
dopts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())}
copts := []grpc.CallOption{grpc.PerRPCCredentials(testLegacyPerRPCCredentials{})}
cc, err := grpc.Dial(addr, dopts...)
cc, err := grpc.NewClient(addr, dopts...)
if err != nil {
t.Fatalf("grpc.Dial(%q) failed: %v", addr, err)
t.Fatalf("grpc.NewClient(%q) failed: %v", addr, err)
}
defer cc.Close()
@ -201,7 +201,7 @@ func (s) TestInsecureCreds_WithPerRPCCredentials_AsDialOption(t *testing.T) {
grpc.WithPerRPCCredentials(testLegacyPerRPCCredentials{}),
}
const wantErr = "the credentials require transport level security"
if _, err := grpc.Dial(addr, dopts...); err == nil || !strings.Contains(err.Error(), wantErr) {
t.Fatalf("grpc.Dial(%q) returned err %v, want: %v", addr, err, wantErr)
if _, err := grpc.NewClient(addr, dopts...); err == nil || !strings.Contains(err.Error(), wantErr) {
t.Fatalf("grpc.NewClient(%q) returned err %v, want: %v", addr, err, wantErr)
}
}

View File

@ -93,7 +93,7 @@ func testLocalCredsE2ESucceed(network, address string) error {
return net.Dial("unix", addr)
}))
case "tcp":
cc, err = grpc.Dial(lisAddr, grpc.WithTransportCredentials(local.NewCredentials()))
cc, err = grpc.NewClient(lisAddr, grpc.WithTransportCredentials(local.NewCredentials()))
default:
return fmt.Errorf("unsupported network %q", network)
}
@ -191,7 +191,7 @@ func testLocalCredsE2EFail(dopts []grpc.DialOption) error {
go s.Serve(spoofListener(lis, fakeClientAddr))
cc, err := grpc.Dial(lis.Addr().String(), append(dopts, grpc.WithDialer(spoofDialer(fakeServerAddr)))...)
cc, err := grpc.NewClient(lis.Addr().String(), append(dopts, grpc.WithDialer(spoofDialer(fakeServerAddr)))...)
if err != nil {
return fmt.Errorf("Failed to dial server: %v, %v", err, lis.Addr().String())
}

View File

@ -80,9 +80,9 @@ func setupPickFirst(t *testing.T, backendCount int, opts ...grpc.DialOption) (*g
grpc.WithDefaultServiceConfig(pickFirstServiceConfig),
}
dopts = append(dopts, opts...)
cc, err := grpc.Dial(r.Scheme()+":///test.server", dopts...)
cc, err := grpc.NewClient(r.Scheme()+":///test.server", dopts...)
if err != nil {
t.Fatalf("grpc.Dial() failed: %v", err)
t.Fatalf("grpc.NewClient() failed: %v", err)
}
t.Cleanup(func() { cc.Close() })
@ -537,9 +537,9 @@ func setupPickFirstWithListenerWrapper(t *testing.T, backendCount int, opts ...g
grpc.WithDefaultServiceConfig(pickFirstServiceConfig),
}
dopts = append(dopts, opts...)
cc, err := grpc.Dial(r.Scheme()+":///test.server", dopts...)
cc, err := grpc.NewClient(r.Scheme()+":///test.server", dopts...)
if err != nil {
t.Fatalf("grpc.Dial() failed: %v", err)
t.Fatalf("grpc.NewClient() failed: %v", err)
}
t.Cleanup(func() { cc.Close() })

View File

@ -56,9 +56,9 @@ func (s) TestResolverUpdateDuringBuild_ServiceConfigParseError(t *testing.T) {
r := manual.NewBuilderWithScheme("whatever")
r.InitialState(resolver.State{ServiceConfig: &serviceconfig.ParseResult{Err: errors.New("resolver build err")}})
cc, err := grpc.Dial(r.Scheme()+":///test.server", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r))
cc, err := grpc.NewClient(r.Scheme()+":///test.server", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r))
if err != nil {
t.Fatalf("Dial(_, _) = _, %v; want _, nil", err)
t.Fatalf("NewClient(_, _) = _, %v; want _, nil", err)
}
defer cc.Close()
@ -88,9 +88,9 @@ func (s) TestResolverUpdateDuringBuild_ServiceConfigInvalidTypeError(t *testing.
r := manual.NewBuilderWithScheme("whatever")
r.InitialState(resolver.State{ServiceConfig: &serviceconfig.ParseResult{Config: fakeConfig{}}})
cc, err := grpc.Dial(r.Scheme()+":///test.server", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r))
cc, err := grpc.NewClient(r.Scheme()+":///test.server", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r))
if err != nil {
t.Fatalf("Dial(_, _) = _, %v; want _, nil", err)
t.Fatalf("NewClient(_, _) = _, %v; want _, nil", err)
}
defer cc.Close()

View File

@ -531,7 +531,7 @@ func (s) TestRetryStats(t *testing.T) {
}
server.start(t, lis)
handler := &retryStatsHandler{}
cc, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithStatsHandler(handler),
cc, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithStatsHandler(handler),
grpc.WithDefaultServiceConfig((`{
"methodConfig": [{
"name": [{"service": "grpc.testing.TestService"}],

View File

@ -72,9 +72,9 @@ func testRoundRobinBasic(ctx context.Context, t *testing.T, opts ...grpc.DialOpt
grpc.WithDefaultServiceConfig(rrServiceConfig),
}
dopts = append(dopts, opts...)
cc, err := grpc.Dial(r.Scheme()+":///test.server", dopts...)
cc, err := grpc.NewClient(r.Scheme()+":///test.server", dopts...)
if err != nil {
t.Fatalf("grpc.Dial() failed: %v", err)
t.Fatalf("grpc.NewClient() failed: %v", err)
}
t.Cleanup(func() { cc.Close() })
client := testgrpc.NewTestServiceClient(cc)

View File

@ -142,7 +142,7 @@ func (s) TestClientResourceVersionAfterStreamRestart(t *testing.T) {
}
// Create a ClientConn and make a successful RPC.
cc, err := grpc.Dial(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(resolver))
cc, err := grpc.NewClient(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(resolver))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
}

View File

@ -115,7 +115,7 @@ func (s) TestClientSideAffinitySanityCheck(t *testing.T) {
}
// Create a ClientConn and make a successful RPC.
cc, err := grpc.Dial(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(resolver))
cc, err := grpc.NewClient(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(resolver))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
}

View File

@ -112,7 +112,7 @@ func (s) TestClientSideXDS_WithNoCertificateProvidersInBootstrap_Success(t *test
}
// Create a ClientConn and make a successful RPC.
cc, err := grpc.Dial(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(creds), grpc.WithResolvers(resolverBuilder))
cc, err := grpc.NewClient(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(creds), grpc.WithResolvers(resolverBuilder))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
}
@ -330,7 +330,7 @@ func (s) TestClientSideXDS_WithValidAndInvalidSecurityConfiguration(t *testing.T
}
// Create a ClientConn.
cc, err := grpc.Dial(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(creds), grpc.WithResolvers(resolver))
cc, err := grpc.NewClient(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(creds), grpc.WithResolvers(resolver))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
}

View File

@ -253,7 +253,7 @@ func (s) TestWrrLocality(t *testing.T) {
t.Fatal(err)
}
cc, err := grpc.Dial(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r))
cc, err := grpc.NewClient(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r))
if err != nil {
t.Fatalf("Failed to dial local test server: %v", err)
}

View File

@ -128,7 +128,7 @@ func (s) TestClientSideFederation(t *testing.T) {
}
// Create a ClientConn and make a successful RPC.
cc, err := grpc.Dial(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(resolver))
cc, err := grpc.NewClient(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(resolver))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
}
@ -213,7 +213,7 @@ func (s) TestClientSideFederationWithOnlyXDSTPStyleLDS(t *testing.T) {
}
// Create a ClientConn and make a successful RPC.
cc, err := grpc.Dial(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(resolver))
cc, err := grpc.NewClient(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(resolver))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
}
@ -258,7 +258,7 @@ func (s) TestFederation_UnknownAuthorityInDialTarget(t *testing.T) {
// Create a ClientConn and make a successful RPC.
target := fmt.Sprintf("xds:///%s", serviceName)
cc, err := grpc.Dial(target, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(resolver))
cc, err := grpc.NewClient(target, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(resolver))
if err != nil {
t.Fatalf("Dialing target %q: %v", target, err)
}
@ -327,7 +327,7 @@ func (s) TestFederation_UnknownAuthorityInReceivedResponse(t *testing.T) {
}
target := fmt.Sprintf("xds:///%s", serviceName)
cc, err := grpc.Dial(target, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(resolver))
cc, err := grpc.NewClient(target, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(resolver))
if err != nil {
t.Fatalf("Dialing target %q: %v", target, err)
}

View File

@ -158,7 +158,7 @@ func testResourceDeletionIgnored(t *testing.T, initialResource func(string) e2e.
t.Fatal(err)
}
cc, err := grpc.Dial(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(xdsR))
cc, err := grpc.NewClient(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(xdsR))
if err != nil {
t.Fatalf("Failed to dial local test server: %v.", err)
}
@ -213,7 +213,7 @@ func testResourceDeletionNotIgnored(t *testing.T, initialResource func(string) e
t.Fatal(err)
}
cc, err := grpc.Dial(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(xdsR))
cc, err := grpc.NewClient(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(xdsR))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
}
@ -375,7 +375,7 @@ func (s) TestListenerResourceDeletionOnServerIgnored(t *testing.T) {
}
// Create a ClientConn and make a successful RPCs.
cc, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(xdsR))
cc, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(xdsR))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
}
@ -442,7 +442,7 @@ func (s) TestListenerResourceDeletionOnServerNotIgnored(t *testing.T) {
}
// Create a ClientConn and make a successful RPCs.
cc, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(xdsR))
cc, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(xdsR))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
}

View File

@ -70,7 +70,7 @@ func (s) TestClientSideXDS(t *testing.T) {
}
// Create a ClientConn and make a successful RPC.
cc, err := grpc.Dial(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(resolver))
cc, err := grpc.NewClient(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(resolver))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
}

View File

@ -75,7 +75,7 @@ func (s) TestOutlierDetection_NoopConfig(t *testing.T) {
}
// Create a ClientConn and make a successful RPC.
cc, err := grpc.Dial(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(resolver))
cc, err := grpc.NewClient(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(resolver))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
}
@ -204,7 +204,7 @@ func (s) TestOutlierDetectionWithOutlier(t *testing.T) {
t.Fatal(err)
}
cc, err := grpc.Dial(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r))
cc, err := grpc.NewClient(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
}
@ -291,7 +291,7 @@ func (s) TestOutlierDetectionXDSDefaultOn(t *testing.T) {
t.Fatal(err)
}
cc, err := grpc.Dial(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r))
cc, err := grpc.NewClient(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
}

View File

@ -69,7 +69,7 @@ func (s) TestClientSideRetry(t *testing.T) {
}
// Create a ClientConn and make a successful RPC.
cc, err := grpc.Dial(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(resolver))
cc, err := grpc.NewClient(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(resolver))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
}

View File

@ -142,7 +142,7 @@ func testRLSinxDS(t *testing.T, lbPolicy e2e.LoadBalancingPolicy) {
})
// Create a ClientConn and make a successful RPC.
cc, err := grpc.Dial(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(resolver))
cc, err := grpc.NewClient(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(resolver))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
}

View File

@ -344,7 +344,7 @@ func (s) TestUnmarshalCluster_WithUpdateValidatorFunc(t *testing.T) {
t.Fatal(err)
}
cc, err := grpc.Dial(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(resolver))
cc, err := grpc.NewClient(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(resolver))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
}

View File

@ -97,7 +97,7 @@ func (s) TestServerSideXDS_WithNoCertificateProvidersInBootstrap_Success(t *test
}
// Create a client that uses insecure creds and verify RPCs.
cc, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("Failed to dial local test server: %v", err)
}
@ -225,7 +225,7 @@ func (s) TestServerSideXDS_WithNoCertificateProvidersInBootstrap_Failure(t *test
// Create a client that uses insecure creds and verify that RPCs don't
// succeed.
cc, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("Failed to dial local test server: %v", err)
}
@ -443,7 +443,7 @@ func (s) TestServerSideXDS_WithValidAndInvalidSecurityConfiguration(t *testing.T
// Create a client that uses TLS creds and verify RPCs to listener1.
clientCreds := e2e.CreateClientTLSCredentials(t)
cc1, err := grpc.Dial(lis1.Addr().String(), grpc.WithTransportCredentials(clientCreds))
cc1, err := grpc.NewClient(lis1.Addr().String(), grpc.WithTransportCredentials(clientCreds))
if err != nil {
t.Fatalf("Failed to dial local test server: %v", err)
}
@ -471,7 +471,7 @@ func (s) TestServerSideXDS_WithValidAndInvalidSecurityConfiguration(t *testing.T
// Create a client that uses insecure creds and verify that RPCs don't
// succeed to listener2.
cc2, err := grpc.Dial(lis2.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
cc2, err := grpc.NewClient(lis2.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("Failed to dial local test server: %v", err)
}

View File

@ -103,7 +103,7 @@ func (s) TestServerSideXDS_RedundantUpdateSuppression(t *testing.T) {
}
// Create a ClientConn and make a successful RPCs.
cc, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
}
@ -265,7 +265,7 @@ func (s) TestServerSideXDS_ServingModeChanges(t *testing.T) {
}
// Create a ClientConn to the first listener and make a successful RPCs.
cc1, err := grpc.Dial(lis1.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
cc1, err := grpc.NewClient(lis1.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
}
@ -273,7 +273,7 @@ func (s) TestServerSideXDS_ServingModeChanges(t *testing.T) {
waitForSuccessfulRPC(ctx, t, cc1)
// Create a ClientConn to the second listener and make a successful RPCs.
cc2, err := grpc.Dial(lis2.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
cc2, err := grpc.NewClient(lis2.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
}

View File

@ -110,7 +110,7 @@ func (s) TestServeLDSRDS(t *testing.T) {
case <-serving.Done():
}
cc, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
}
@ -214,7 +214,7 @@ func (s) TestRDSNack(t *testing.T) {
}
}()
cc, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
}
@ -277,7 +277,7 @@ func (s) TestResourceNotFoundRDS(t *testing.T) {
}
}()
cc, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
}
@ -358,7 +358,7 @@ func (s) TestServingModeChanges(t *testing.T) {
t.Errorf("Serve() failed: %v", err)
}
}()
cc, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
}
@ -471,7 +471,7 @@ func (s) TestMultipleUpdatesImmediatelySwitch(t *testing.T) {
}
}()
cc, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
}

View File

@ -165,7 +165,7 @@ func (s) TestCSDS(t *testing.T) {
}()
// Create a client to the CSDS server.
conn, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("Failed to dial CSDS server %q: %v", lis.Addr().String(), err)
}
@ -434,7 +434,7 @@ func (s) TestCSDSNoXDSClient(t *testing.T) {
defer server.Stop()
// Create a client to the CSDS server.
conn, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("Failed to dial CSDS server %q: %v", lis.Addr().String(), err)
}

View File

@ -92,7 +92,7 @@ func (s) TestConfigUpdateWithSameLoadReportingServerConfig(t *testing.T) {
}
// Create a ClientConn and make a successful RPC.
cc, err := grpc.Dial(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(resolver))
cc, err := grpc.NewClient(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(resolver))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
}

View File

@ -221,9 +221,9 @@ func (s) TestOutlierDetectionAlgorithmsE2E(t *testing.T) {
ServiceConfig: sc,
})
cc, err := grpc.Dial(mr.Scheme()+":///", grpc.WithResolvers(mr), grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(mr.Scheme()+":///", grpc.WithResolvers(mr), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("grpc.Dial() failed: %v", err)
t.Fatalf("grpc.NewClient() failed: %v", err)
}
defer cc.Close()
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
@ -298,9 +298,9 @@ func (s) TestNoopConfiguration(t *testing.T) {
Addresses: fullAddresses,
ServiceConfig: sc,
})
cc, err := grpc.Dial(mr.Scheme()+":///", grpc.WithResolvers(mr), grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(mr.Scheme()+":///", grpc.WithResolvers(mr), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("grpc.Dial() failed: %v", err)
t.Fatalf("grpc.NewClient() failed: %v", err)
}
defer cc.Close()
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)

View File

@ -529,7 +529,7 @@ func (s) TestFaultInjection_Unary(t *testing.T) {
}
// Create a ClientConn and run the test case.
cc, err := grpc.Dial("xds:///"+serviceName, grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient("xds:///"+serviceName, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
}
@ -605,7 +605,7 @@ func (s) TestFaultInjection_MaxActiveFaults(t *testing.T) {
}
// Create a ClientConn
cc, err := grpc.Dial("xds:///myservice", grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient("xds:///myservice", grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
}

View File

@ -168,7 +168,7 @@ func (s) TestCaReloading(t *testing.T) {
serverCredentials := grpc.Creds(e2e.CreateServerTLSCredentials(t, tls.NoClientCert))
server := stubserver.StartTestService(t, nil, serverCredentials)
conn, err := grpc.Dial(
conn, err := grpc.NewClient(
server.Address,
grpc.WithCredentialsBundle(tlsBundle),
grpc.WithAuthority("x.test.example.com"),
@ -241,7 +241,7 @@ func (s) TestMTLS(t *testing.T) {
t.Fatalf("Failed to create TLS bundle: %v", err)
}
defer stop()
conn, err := grpc.Dial(s.Address, grpc.WithCredentialsBundle(tlsBundle), grpc.WithAuthority("x.test.example.com"))
conn, err := grpc.NewClient(s.Address, grpc.WithCredentialsBundle(tlsBundle), grpc.WithAuthority("x.test.example.com"))
if err != nil {
t.Fatalf("Error dialing: %v", err)
}

View File

@ -78,7 +78,7 @@ func (s) TestFailingProvider(t *testing.T) {
}
creds.provider = &failingProvider{}
conn, err := grpc.Dial(s.Address, grpc.WithCredentialsBundle(tlsBundle), grpc.WithAuthority("x.test.example.com"))
conn, err := grpc.NewClient(s.Address, grpc.WithCredentialsBundle(tlsBundle), grpc.WithAuthority("x.test.example.com"))
if err != nil {
t.Fatalf("Error dialing: %v", err)
}

View File

@ -39,7 +39,7 @@ func (s) TestNewWithGRPCDial(t *testing.T) {
customDialerCalled := false
customDialer := func(target string, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
customDialerCalled = true
return grpc.Dial(target, opts...)
return grpc.NewClient(target, opts...)
}
oldDial := grpcDial
grpcDial = customDialer
@ -66,7 +66,7 @@ func (s) TestNewWithGRPCDial(t *testing.T) {
// Reset the dialer, create a new transport and ensure that our custom
// dialer is no longer called.
grpcDial = grpc.Dial
grpcDial = grpc.NewClient
c, err = New(opts)
defer func() {
if c != nil {