diff --git a/orca/producer_test.go b/orca/producer_test.go index 9df18bf574c9..103329837f2f 100644 --- a/orca/producer_test.go +++ b/orca/producer_test.go @@ -153,12 +153,12 @@ func (s) TestProducer(t *testing.T) { li := &listenerInfo{scChan: make(chan balancer.SubConn, 1), listener: oobLis, opts: lisOpts} addr := setListenerInfo(resolver.Address{Addr: lis.Addr().String()}, li) r.InitialState(resolver.State{Addresses: []resolver.Address{addr}}) - cc, err := grpc.Dial("whatever:///whatever", grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"customLB":{}}]}`), grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials())) + cc, err := grpc.NewClient("whatever:///whatever", grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"customLB":{}}]}`), grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { - t.Fatalf("grpc.Dial failed: %v", err) + t.Fatalf("grpc.NewClient() failed: %v", err) } defer cc.Close() - + cc.Connect() // Set a few metrics and wait for them on the client side. smr.SetCPUUtilization(10) smr.SetMemoryUtilization(0.1) @@ -319,10 +319,11 @@ func (s) TestProducerBackoff(t *testing.T) { lisOpts := orca.OOBListenerOptions{ReportInterval: reportInterval} li := &listenerInfo{scChan: make(chan balancer.SubConn, 1), listener: oobLis, opts: lisOpts} r.InitialState(resolver.State{Addresses: []resolver.Address{setListenerInfo(resolver.Address{Addr: lis.Addr().String()}, li)}}) - cc, err := grpc.Dial("whatever:///whatever", grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"customLB":{}}]}`), grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials())) + cc, err := grpc.NewClient("whatever:///whatever", grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"customLB":{}}]}`), grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { - t.Fatalf("grpc.Dial failed: %v", err) + t.Fatalf("grpc.NewClient failed: %v", err) } + cc.Connect() defer cc.Close() // Define a load report to send and expect the client to see. @@ -431,10 +432,11 @@ func (s) TestProducerMultipleListeners(t *testing.T) { lisOpts1 := orca.OOBListenerOptions{ReportInterval: reportInterval1} li := &listenerInfo{scChan: make(chan balancer.SubConn, 1), listener: oobLis1, opts: lisOpts1} r.InitialState(resolver.State{Addresses: []resolver.Address{setListenerInfo(resolver.Address{Addr: lis.Addr().String()}, li)}}) - cc, err := grpc.Dial("whatever:///whatever", grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"customLB":{}}]}`), grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials())) + cc, err := grpc.NewClient("whatever:///whatever", grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"customLB":{}}]}`), grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { - t.Fatalf("grpc.Dial failed: %v", err) + t.Fatalf("grpc.NewClient() failed: %v", err) } + cc.Connect() defer cc.Close() // Ensure the OOB listener is stopped before the client is closed to avoid diff --git a/resolver/manual/manual_test.go b/resolver/manual/manual_test.go index 3c118134b870..b4882d3d229d 100644 --- a/resolver/manual/manual_test.go +++ b/resolver/manual/manual_test.go @@ -59,15 +59,17 @@ func TestResolver(t *testing.T) { }) t.Run("happy_path", func(t *testing.T) { - _, err := grpc.Dial("whatever://localhost", + r.InitialState(resolver.State{Addresses: []resolver.Address{ + {Addr: "ok"}, + }}) + cc, err := grpc.NewClient("whatever://localhost", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r)) if err != nil { - t.Errorf("dial setup error: %v", err) + t.Errorf("grpc.NewClient() failed: %v", err) } - r.UpdateState(resolver.State{Addresses: []resolver.Address{ - {Addr: "ok"}, - }}) + defer cc.Close() + cc.Connect() r.ReportError(errors.New("example")) }) } diff --git a/test/authority_test.go b/test/authority_test.go index cf9da155a770..04d7ed021e2b 100644 --- a/test/authority_test.go +++ b/test/authority_test.go @@ -165,7 +165,7 @@ func (s) TestUnixCustomDialer(t *testing.T) { } } -// TestColonPortAuthority does an end to end test with the target for grpc.Dial +// TestColonPortAuthority does an end to end test with the target for grpc.NewClient // being ":[port]". Ensures authority is "localhost:[port]". func (s) TestColonPortAuthority(t *testing.T) { expectedAuthority := "" @@ -194,11 +194,14 @@ func (s) TestColonPortAuthority(t *testing.T) { // // Append "localhost" before calling net.Dial, in case net.Dial on certain // platforms doesn't work well for address without the IP. - cc, err := grpc.Dial(":"+port, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) { - return (&net.Dialer{}).DialContext(ctx, "tcp", "localhost"+addr) + cc, err := grpc.NewClient(":"+port, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) { + if len(addr) > 0 && addr[0] == ':' { + addr = "localhost" + addr + } + return (&net.Dialer{}).DialContext(ctx, "tcp", addr) })) if err != nil { - t.Fatalf("grpc.Dial(%q) = %v", ss.Target, err) + t.Fatalf("grpc.NewClient(%q) = %v", ss.Target, err) } defer cc.Close() ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) diff --git a/test/roundrobin_test.go b/test/roundrobin_test.go index 2241fab7e6c8..e27e8d33b834 100644 --- a/test/roundrobin_test.go +++ b/test/roundrobin_test.go @@ -266,16 +266,15 @@ func (s) TestRoundRobin_UpdateAddressAttributes(t *testing.T) { grpc.WithResolvers(r), grpc.WithDefaultServiceConfig(rrServiceConfig), } - cc, err := grpc.Dial(r.Scheme()+":///test.server", dopts...) + // Send a resolver update with no address attributes. + addr := resolver.Address{Addr: backend.Address} + r.InitialState(resolver.State{Addresses: []resolver.Address{addr}}) + 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() }) - // Send a resolver update with no address attributes. - addr := resolver.Address{Addr: backend.Address} - r.UpdateState(resolver.State{Addresses: []resolver.Address{addr}}) - // Make an RPC and ensure it does not contain the metadata we are looking for. client := testgrpc.NewTestServiceClient(cc) ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)