diff --git a/internal/idle/idle_e2e_test.go b/internal/idle/idle_e2e_test.go index 12d8e5e24409..fd902f4c0af4 100644 --- a/internal/idle/idle_e2e_test.go +++ b/internal/idle/idle_e2e_test.go @@ -136,19 +136,16 @@ func (s) TestChannelIdleness_Disabled_NoActivity(t *testing.T) { t.Fatalf("grpc.NewClient() failed: %v", err) } defer cc.Close() + cc.Connect() // Start a test backend and push an address update via the resolver. backend := stubserver.StartTestService(t, nil) defer backend.Stop() - r.InitialState(resolver.State{Addresses: []resolver.Address{{Addr: backend.Address}}}) + r.UpdateState(resolver.State{Addresses: []resolver.Address{{Addr: backend.Address}}}) - // Trigger the resolver by initiating an RPC. + // Verify that the ClientConn moves to READY. 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. @@ -186,20 +183,16 @@ func (s) TestChannelIdleness_Enabled_NoActivity(t *testing.T) { t.Fatalf("grpc.NewClient() failed: %v", err) } defer cc.Close() - + cc.Connect() // 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.InitialState(resolver.State{Addresses: []resolver.Address{{Addr: backend.Address}}}) + r.UpdateState(resolver.State{Addresses: []resolver.Address{{Addr: backend.Address}}}) - // Verify that the ClientConn moves to READY and trigger the resolver by - // initiating an RPC. + // Verify that the ClientConn moves to READY. 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. @@ -278,7 +271,7 @@ func (s) TestChannelIdleness_Enabled_OngoingCall(t *testing.T) { t.Fatalf("grpc.NewClient() failed: %v", err) } defer cc.Close() - + cc.Connect() // Start a test backend that keeps the RPC call active by blocking // on a channel that is closed by the test later on. blockCh := make(chan struct{}) @@ -299,15 +292,11 @@ func (s) TestChannelIdleness_Enabled_OngoingCall(t *testing.T) { // Push an address update containing the address of the above // backend via the manual resolver. - r.InitialState(resolver.State{Addresses: []resolver.Address{{Addr: backend.Address}}}) + r.UpdateState(resolver.State{Addresses: []resolver.Address{{Addr: backend.Address}}}) - // Verify that the ClientConn moves to READY and trigger the resolver by - // initiating an RPC. + // Verify that the ClientConn moves to READY. 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 @@ -371,19 +360,15 @@ func (s) TestChannelIdleness_Enabled_ActiveSinceLastCheck(t *testing.T) { t.Fatalf("grpc.NewClient() failed: %v", err) } defer cc.Close() - + cc.Connect() // Start a test backend and push an address update via the resolver. backend := stubserver.StartTestService(t, nil) defer backend.Stop() - r.InitialState(resolver.State{Addresses: []resolver.Address{{Addr: backend.Address}}}) + r.UpdateState(resolver.State{Addresses: []resolver.Address{{Addr: backend.Address}}}) - // Verify that the ClientConn moves to READY and trigger the resolver by - // initiating an RPC. + // Verify that the ClientConn moves to READY. 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 @@ -444,15 +429,10 @@ func (s) TestChannelIdleness_Enabled_ExitIdleOnRPC(t *testing.T) { t.Fatalf("grpc.NewClient() failed: %v", err) } defer cc.Close() - - // Verify that the ClientConn moves to READY and trigger the resolver by - // initiating an RPC. + cc.Connect() + // Verify that the ClientConn moves to READY. 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. diff --git a/orca/producer_test.go b/orca/producer_test.go index 103329837f2f..adf030cc145b 100644 --- a/orca/producer_test.go +++ b/orca/producer_test.go @@ -153,7 +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.NewClient("whatever:///whatever", grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"customLB":{}}]}`), grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials())) + dopts := []grpc.DialOption{ + grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"customLB":{}}]}`), + grpc.WithResolvers(r), + grpc.WithTransportCredentials(insecure.NewCredentials()), + } + cc, err := grpc.NewClient("whatever:///whatever", dopts...) if err != nil { t.Fatalf("grpc.NewClient() failed: %v", err) } @@ -319,7 +324,12 @@ 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.NewClient("whatever:///whatever", grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"customLB":{}}]}`), grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials())) + dopts := []grpc.DialOption{ + grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"customLB":{}}]}`), + grpc.WithResolvers(r), + grpc.WithTransportCredentials(insecure.NewCredentials()), + } + cc, err := grpc.NewClient("whatever:///whatever", dopts...) if err != nil { t.Fatalf("grpc.NewClient failed: %v", err) } diff --git a/resolver/manual/manual_test.go b/resolver/manual/manual_test.go index b4882d3d229d..2d089268b778 100644 --- a/resolver/manual/manual_test.go +++ b/resolver/manual/manual_test.go @@ -59,9 +59,6 @@ func TestResolver(t *testing.T) { }) t.Run("happy_path", func(t *testing.T) { - r.InitialState(resolver.State{Addresses: []resolver.Address{ - {Addr: "ok"}, - }}) cc, err := grpc.NewClient("whatever://localhost", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r)) @@ -70,6 +67,9 @@ func TestResolver(t *testing.T) { } defer cc.Close() cc.Connect() + r.UpdateState(resolver.State{Addresses: []resolver.Address{ + {Addr: "ok"}, + }}) r.ReportError(errors.New("example")) }) } diff --git a/test/authority_test.go b/test/authority_test.go index 04d7ed021e2b..302376409c86 100644 --- a/test/authority_test.go +++ b/test/authority_test.go @@ -194,12 +194,7 @@ 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.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) - })) + cc, err := grpc.NewClient(":"+port, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { t.Fatalf("grpc.NewClient(%q) = %v", ss.Target, err) } diff --git a/test/roundrobin_test.go b/test/roundrobin_test.go index e27e8d33b834..815e244946fe 100644 --- a/test/roundrobin_test.go +++ b/test/roundrobin_test.go @@ -266,7 +266,7 @@ func (s) TestRoundRobin_UpdateAddressAttributes(t *testing.T) { grpc.WithResolvers(r), grpc.WithDefaultServiceConfig(rrServiceConfig), } - // Send a resolver update with no address attributes. + // Set an initial 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...)