Skip to content
25 changes: 15 additions & 10 deletions balancer/rls/balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,12 @@ func (s) TestConfigUpdate_ChildPolicyConfigs(t *testing.T) {
// Register a manual resolver and push the RLS service config through it.
r := startManualResolverWithConfig(t, rlsConfig)

cc, err := grpc.Dial(r.Scheme()+":///", grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(r.Scheme()+":///", 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()

// At this point, the RLS LB policy should have received its config, and
// should have created a child policy for the default target.
Expand Down Expand Up @@ -448,11 +449,12 @@ func (s) TestConfigUpdate_ChildPolicyChange(t *testing.T) {
// Register a manual resolver and push the RLS service config through it.
r := startManualResolverWithConfig(t, rlsConfig)

cc, err := grpc.Dial(r.Scheme()+":///", grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(r.Scheme()+":///", 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()

// At this point, the RLS LB policy should have received its config, and
// should have created a child policy for the default target.
Expand Down Expand Up @@ -603,11 +605,12 @@ func (s) TestConfigUpdate_DataCacheSizeDecrease(t *testing.T) {
// Register a manual resolver and push the RLS service config through it.
r := startManualResolverWithConfig(t, rlsConfig)

cc, err := grpc.Dial(r.Scheme()+":///", grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(r.Scheme()+":///", 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()

<-clientConnUpdateDone

Expand Down Expand Up @@ -769,11 +772,12 @@ func (s) TestPickerUpdateOnDataCacheSizeDecrease(t *testing.T) {
sc := internal.ParseServiceConfig.(func(string) *serviceconfig.ParseResult)(scJSON)
r.InitialState(resolver.State{ServiceConfig: sc})

cc, err := grpc.Dial(r.Scheme()+":///", grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(r.Scheme()+":///", grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("create grpc.Dial() failed: %v", err)
t.Fatalf("create grpc.NewClient() failed: %v", err)
}
defer cc.Close()
cc.Connect()

<-clientConnUpdateDone

Expand Down Expand Up @@ -1151,11 +1155,12 @@ func (s) TestUpdateStatePauses(t *testing.T) {
sc := internal.ParseServiceConfig.(func(string) *serviceconfig.ParseResult)(scJSON)
r.InitialState(resolver.State{ServiceConfig: sc})

cc, err := grpc.Dial(r.Scheme()+":///", grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(r.Scheme()+":///", 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()

// Wait for the clientconn update to be processed by the RLS LB policy.
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
Expand Down
59 changes: 40 additions & 19 deletions internal/idle/idle_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,24 @@ func (s) TestChannelIdleness_Disabled_NoActivity(t *testing.T) {
grpc.WithIdleTimeout(0), // Disable idleness.
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()

// Start a test backend and push an address update via the resolver.
backend := stubserver.StartTestService(t, nil)
defer backend.Stop()
r.UpdateState(resolver.State{Addresses: []resolver.Address{{Addr: backend.Address}}})
r.InitialState(resolver.State{Addresses: []resolver.Address{{Addr: backend.Address}}})

// Verify that the ClientConn moves to READY.
// Trigger the resolver by initiating an RPC.
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()
go func() {
_ = cc.Invoke(ctx, "/test/method", nil, nil)
}()
// Verify that the ClientConn moves to READY.
testutils.AwaitState(ctx, t, cc, connectivity.Ready)

// Verify that the ClientConn stays in READY.
Expand Down Expand Up @@ -177,21 +181,25 @@ func (s) TestChannelIdleness_Enabled_NoActivity(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()

// Start a test backend and push an address update via the resolver.
lis := testutils.NewListenerWrapper(t, nil)
backend := stubserver.StartTestService(t, &stubserver.StubServer{Listener: lis})
defer backend.Stop()
r.UpdateState(resolver.State{Addresses: []resolver.Address{{Addr: backend.Address}}})
r.InitialState(resolver.State{Addresses: []resolver.Address{{Addr: backend.Address}}})

// Verify that the ClientConn moves to READY.
// Verify that the ClientConn moves to READY and trigger the resolver by
// initiating an RPC.
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()
go func() {
_ = cc.Invoke(ctx, "/test/method", nil, nil)
}()
testutils.AwaitState(ctx, t, cc, connectivity.Ready)

// Retrieve the wrapped conn from the listener.
Expand Down Expand Up @@ -265,9 +273,9 @@ func (s) TestChannelIdleness_Enabled_OngoingCall(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()

Expand All @@ -291,11 +299,15 @@ func (s) TestChannelIdleness_Enabled_OngoingCall(t *testing.T) {

// Push an address update containing the address of the above
// backend via the manual resolver.
r.UpdateState(resolver.State{Addresses: []resolver.Address{{Addr: backend.Address}}})
r.InitialState(resolver.State{Addresses: []resolver.Address{{Addr: backend.Address}}})

// Verify that the ClientConn moves to READY.
// Verify that the ClientConn moves to READY and trigger the resolver by
// initiating an RPC.
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()
go func() {
_ = cc.Invoke(ctx, "/test/method", nil, nil)
}()
testutils.AwaitState(ctx, t, cc, connectivity.Ready)

// Spawn a goroutine to check for expected behavior while a blocking
Expand Down Expand Up @@ -354,20 +366,24 @@ func (s) TestChannelIdleness_Enabled_ActiveSinceLastCheck(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()

// Start a test backend and push an address update via the resolver.
backend := stubserver.StartTestService(t, nil)
defer backend.Stop()
r.UpdateState(resolver.State{Addresses: []resolver.Address{{Addr: backend.Address}}})
r.InitialState(resolver.State{Addresses: []resolver.Address{{Addr: backend.Address}}})

// Verify that the ClientConn moves to READY.
// Verify that the ClientConn moves to READY and trigger the resolver by
// initiating an RPC.
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()
go func() {
_ = cc.Invoke(ctx, "/test/method", nil, nil)
}()
testutils.AwaitState(ctx, t, cc, connectivity.Ready)

// For a duration of three times the configured idle timeout, making RPCs
Expand Down Expand Up @@ -423,15 +439,20 @@ func (s) TestChannelIdleness_Enabled_ExitIdleOnRPC(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()

// Verify that the ClientConn moves to READY.
// Verify that the ClientConn moves to READY and trigger the resolver by
// initiating an RPC.
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()
go func() {
_ = cc.Invoke(ctx, "/test/method", nil, nil)
}()

testutils.AwaitState(ctx, t, cc, connectivity.Ready)

// Verify that the ClientConn moves to IDLE as there is no activity.
Expand Down
16 changes: 9 additions & 7 deletions orca/producer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions resolver/manual/manual_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})
}
11 changes: 7 additions & 4 deletions test/authority_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := ""
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 5 additions & 6 deletions test/roundrobin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading