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

cleanup: replace dial with newclient #7967

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
18 changes: 9 additions & 9 deletions test/clientconn_state_transition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,14 @@ func (s) TestStateTransitions_ReadyToConnecting(t *testing.T) {
conn.Close()
}()

client, err := grpc.Dial(lis.Addr().String(),
client, err := grpc.NewClient(lis.Addr().String(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"loadBalancingConfig": [{"%s":{}}]}`, stateRecordingBalancerName)))
if err != nil {
t.Fatal(err)
}
defer client.Close()

client.Connect()
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()
go testutils.StayConnected(ctx, client)
Expand Down Expand Up @@ -324,7 +324,7 @@ func (s) TestStateTransitions_TriesAllAddrsBeforeTransientFailure(t *testing.T)
{Addr: lis1.Addr().String()},
{Addr: lis2.Addr().String()},
}})
client, err := grpc.Dial("whatever:///this-gets-overwritten",
client, err := grpc.NewClient("whatever:///this-gets-overwritten",
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"loadBalancingConfig": [{"%s":{}}]}`, stateRecordingBalancerName)),
grpc.WithConnectParams(grpc.ConnectParams{
Expand All @@ -339,7 +339,7 @@ func (s) TestStateTransitions_TriesAllAddrsBeforeTransientFailure(t *testing.T)
t.Fatal(err)
}
defer client.Close()

client.Connect()
stateNotifications := testBalancerBuilder.nextStateNotifier()
want := []connectivity.State{
connectivity.Connecting,
Expand Down Expand Up @@ -427,15 +427,15 @@ func (s) TestStateTransitions_MultipleAddrsEntersReady(t *testing.T) {
{Addr: lis1.Addr().String()},
{Addr: lis2.Addr().String()},
}})
client, err := grpc.Dial("whatever:///this-gets-overwritten",
client, err := grpc.NewClient("whatever:///this-gets-overwritten",
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"loadBalancingConfig": [{"%s":{}}]}`, stateRecordingBalancerName)),
grpc.WithResolvers(rb))
if err != nil {
t.Fatal(err)
}
defer client.Close()

client.Connect()
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()
go testutils.StayConnected(ctx, client)
Expand Down Expand Up @@ -571,15 +571,15 @@ func (s) TestConnectivityStateSubscriber(t *testing.T) {
// Create the ClientConn.
const testResName = "any"
rb := manual.NewBuilderWithScheme(testResName)
cc, err := grpc.Dial(testResName+":///",
cc, err := grpc.NewClient(testResName+":///",
grpc.WithResolvers(rb),
grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"loadBalancingConfig": [{"%s":{}}]}`, testBalName)),
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
t.Fatalf("Unexpected error from grpc.Dial: %v", err)
t.Fatalf("failed to create a client for server: %v", err)
}

cc.Connect()
// Subscribe to state updates. Use a buffer size of 1 to allow the
// Shutdown state to go into the channel when Close()ing.
connCh := make(chan connectivity.State, 1)
Expand Down
6 changes: 2 additions & 4 deletions test/gracefulstop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,9 @@ func (s) TestGracefulStop(t *testing.T) {

// Now dial. The listener's Accept method will return a valid connection,
// even though GracefulStop has closed the listener.
ctx, dialCancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer dialCancel()
cc, err := grpc.DialContext(ctx, "", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithContextDialer(d))
cc, err := grpc.NewClient("localhost:0", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithContextDialer(d))
if err != nil {
t.Fatalf("grpc.DialContext(_, %q, _) = %v", lis.Addr().String(), err)
t.Fatalf("grpc.NewClient(_, %q, _) = %v", lis.Addr().String(), err)
}
client := testgrpc.NewTestServiceClient(cc)
defer cc.Close()
Expand Down
4 changes: 2 additions & 2 deletions test/xds/xds_security_config_nack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ func (s) TestUnmarshalListener_WithUpdateValidatorFunc(t *testing.T) {
}

// Create a ClientConn with the xds scheme and make an RPC.
cc, err := grpc.DialContext(ctx, fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(creds), grpc.WithResolvers(xdsResolver))
cc, err := grpc.NewClient(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(creds), grpc.WithResolvers(xdsResolver))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
t.Fatalf("failed to create a client for server: %v", err)
}
defer cc.Close()

Expand Down
12 changes: 6 additions & 6 deletions test/xds/xds_server_rbac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ func (s) TestServerSideXDS_RouteConfiguration(t *testing.T) {
t.Fatal(err)
}

cc, err := grpc.DialContext(ctx, fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(xdsResolver))
cc, err := grpc.NewClient(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(xdsResolver))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
t.Fatalf("failed to create a client for server: %v", err)
}
defer cc.Close()

Expand Down Expand Up @@ -654,9 +654,9 @@ func (s) TestRBACHTTPFilter(t *testing.T) {
t.Fatal(err)
}

cc, err := grpc.DialContext(ctx, fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(xdsResolver))
cc, err := grpc.NewClient(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(xdsResolver))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
t.Fatalf("failed to create a client for server: %v", err)
}
defer cc.Close()

Expand Down Expand Up @@ -836,9 +836,9 @@ func (s) TestRBACToggledOn_WithBadRouteConfiguration(t *testing.T) {
t.Fatal(err)
}

cc, err := grpc.DialContext(ctx, fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(xdsResolver))
cc, err := grpc.NewClient(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(xdsResolver))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
t.Fatalf("failed to create a client for server: %v", err)
}
defer cc.Close()

Expand Down
13 changes: 5 additions & 8 deletions test/xds/xds_server_serving_mode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,15 @@ func (s) TestServerSideXDS_ServingModeChanges(t *testing.T) {
// Create a ClientConn to the first listener and make a successful RPCs.
cc1, err := grpc.NewClient(lis1.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
t.Fatalf("failed to create a client for server: %v", err)
}
defer cc1.Close()
waitForSuccessfulRPC(ctx, t, cc1)

// Create a ClientConn to the second listener and make a successful RPCs.
cc2, err := grpc.NewClient(lis2.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("failed to dial local test server: %v", err)
t.Fatalf("failed to create a client for server: %v", err)
}
defer cc2.Close()
waitForSuccessfulRPC(ctx, t, cc2)
Expand Down Expand Up @@ -309,14 +309,11 @@ func (s) TestServerSideXDS_ServingModeChanges(t *testing.T) {
waitForFailedRPC(ctx, t, cc1)
waitForFailedRPC(ctx, t, cc2)

// Make sure new connection attempts to "not-serving" servers fail. We use a
// short timeout since we expect this to fail.
sCtx, sCancel := context.WithTimeout(ctx, defaultTestShortTimeout)
defer sCancel()
if _, err := grpc.DialContext(sCtx, lis1.Addr().String(), grpc.WithBlock(), grpc.WithTransportCredentials(insecure.NewCredentials())); err == nil {
// Make sure new connection attempts to "not-serving" servers fail.
if cc1, err = grpc.NewClient(lis1.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()); err != nil {
t.Fatal("successfully created clientConn to a server in \"not-serving\" state")
}

defer cc1.Close()
// Update the management server with both listener resources.
if err := managementServer.Update(ctx, e2e.UpdateOptions{
NodeID: nodeID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,11 @@ func setupForSecurityTests(t *testing.T, bootstrapContents []byte, clientCreds,
r.InitialState(state)

// Create a ClientConn with the specified transport credentials.
cc, err := grpc.Dial(r.Scheme()+":///test.service", grpc.WithTransportCredentials(clientCreds), grpc.WithResolvers(r))
cc, err := grpc.NewClient(r.Scheme()+":///test.service", grpc.WithTransportCredentials(clientCreds), grpc.WithResolvers(r))
if err != nil {
t.Fatalf("Failed to dial local test server: %v", err)
t.Fatalf("NewClient() failed: %v", err)
}
cc.Connect()
t.Cleanup(func() { cc.Close() })

// Start a test service backend with the specified transport credentials.
Expand Down
15 changes: 9 additions & 6 deletions xds/internal/balancer/cdsbalancer/cdsbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,11 @@ func setupWithManagementServerAndListener(t *testing.T, lis net.Listener) (*e2e.
scpr := internal.ParseServiceConfig.(func(string) *serviceconfig.ParseResult)(jsonSC)
r.InitialState(xdsclient.SetClient(resolver.State{ServiceConfig: scpr}, xdsC))

cc, err := grpc.Dial(r.Scheme()+":///test.service", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r))
cc, err := grpc.NewClient(r.Scheme()+":///test.service", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r))
if err != nil {
t.Fatalf("Failed to dial local test server: %v", err)
t.Fatalf("failed to create a client for server: %v", err)
}
cc.Connect()
t.Cleanup(func() { cc.Close() })

return mgmtServer, nodeID, cc, r, xdsC, cdsResourceRequestedCh, cdsResourceCanceledCh
Expand Down Expand Up @@ -392,10 +393,11 @@ func (s) TestConfigurationUpdate_EmptyCluster(t *testing.T) {
r.InitialState(xdsclient.SetClient(resolver.State{ServiceConfig: scpr}, xdsClient))

// Create a ClientConn with the above manual resolver.
cc, err := grpc.Dial(r.Scheme()+":///test.service", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r))
cc, err := grpc.NewClient(r.Scheme()+":///test.service", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r))
if err != nil {
t.Fatalf("Failed to dial: %v", err)
t.Fatalf("failed to create a client for server: %v", err)
}
cc.Connect()
t.Cleanup(func() { cc.Close() })

select {
Expand Down Expand Up @@ -429,10 +431,11 @@ func (s) TestConfigurationUpdate_MissingXdsClient(t *testing.T) {
r.InitialState(resolver.State{ServiceConfig: scpr})

// Create a ClientConn with the above manual resolver.
cc, err := grpc.Dial(r.Scheme()+":///test.service", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r))
cc, err := grpc.NewClient(r.Scheme()+":///test.service", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r))
if err != nil {
t.Fatalf("Failed to dial: %v", err)
t.Fatalf("failed to create a client for server: %v", err)
}
cc.Connect()
t.Cleanup(func() { cc.Close() })

select {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,12 @@ func setupAndDial(t *testing.T, bootstrapContents []byte) (*grpc.ClientConn, fun
r.InitialState(xdsclient.SetClient(resolver.State{ServiceConfig: scpr}, xdsC))

// Create a ClientConn and make a successful RPC.
cc, err := grpc.Dial(r.Scheme()+":///test.service", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r))
cc, err := grpc.NewClient(r.Scheme()+":///test.service", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r))
if err != nil {
xdsClose()
t.Fatalf("Failed to dial local test server: %v", err)
t.Fatalf("failed to create a client for server: %v", err)
}
cc.Connect()
return cc, func() {
xdsClose()
cc.Close()
Expand Down
Loading