From c9cca95c239fc495a1ce89be2dc7aa0f3a889f67 Mon Sep 17 00:00:00 2001 From: Easwar Swaminathan Date: Tue, 7 Oct 2025 15:09:49 -0700 Subject: [PATCH] clusterimpl: remove unused code in tests (#8634) RELEASE NOTES: NONE --- .../xds/balancer/clusterimpl/balancer_test.go | 12 +++------- internal/xds/xdsclient/requests_counter.go | 24 ------------------- 2 files changed, 3 insertions(+), 33 deletions(-) diff --git a/internal/xds/balancer/clusterimpl/balancer_test.go b/internal/xds/balancer/clusterimpl/balancer_test.go index c7ea56c6..9f55c606 100644 --- a/internal/xds/balancer/clusterimpl/balancer_test.go +++ b/internal/xds/balancer/clusterimpl/balancer_test.go @@ -67,9 +67,6 @@ func init() { // are handled in the run() goroutine, which exits before Close() returns, we // expect the above picker update to be dropped. func (s) TestPickerUpdateAfterClose(t *testing.T) { - defer xdsclient.ClearCounterForTesting(testClusterName, testServiceName) - xdsC := fakeclient.NewClient() - builder := balancer.Get(Name) cc := testutils.NewBalancerClientConn(t) b := builder.Build(cc, balancer.BuildOptions{}) @@ -104,6 +101,7 @@ func (s) TestPickerUpdateAfterClose(t *testing.T) { }) var maxRequest uint32 = 50 + xdsC := fakeclient.NewClient() if err := b.UpdateClientConnState(balancer.ClientConnState{ ResolverState: xdsclient.SetClient(resolver.State{Endpoints: testBackendEndpoints}, xdsC), BalancerConfig: &LBConfig{ @@ -140,14 +138,12 @@ func (s) TestClusterNameInAddressAttributes(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) defer cancel() - defer xdsclient.ClearCounterForTesting(testClusterName, testServiceName) - xdsC := fakeclient.NewClient() - builder := balancer.Get(Name) cc := testutils.NewBalancerClientConn(t) b := builder.Build(cc, balancer.BuildOptions{}) defer b.Close() + xdsC := fakeclient.NewClient() if err := b.UpdateClientConnState(balancer.ClientConnState{ ResolverState: xdsclient.SetClient(resolver.State{Endpoints: testBackendEndpoints}, xdsC), BalancerConfig: &LBConfig{ @@ -237,9 +233,6 @@ func (s) TestPickerUpdatedSynchronouslyOnConfigUpdate(t *testing.T) { } defer func() { clientConnUpdateHook = origClientConnUpdateHook }() - defer xdsclient.ClearCounterForTesting(testClusterName, testServiceName) - xdsC := fakeclient.NewClient() - builder := balancer.Get(Name) cc := testutils.NewBalancerClientConn(t) b := builder.Build(cc, balancer.BuildOptions{}) @@ -257,6 +250,7 @@ func (s) TestPickerUpdatedSynchronouslyOnConfigUpdate(t *testing.T) { }, }) + xdsC := fakeclient.NewClient() if err := b.UpdateClientConnState(balancer.ClientConnState{ ResolverState: xdsclient.SetClient(resolver.State{Endpoints: testBackendEndpoints}, xdsC), BalancerConfig: &LBConfig{ diff --git a/internal/xds/xdsclient/requests_counter.go b/internal/xds/xdsclient/requests_counter.go index bd08c7e1..08f38bb1 100644 --- a/internal/xds/xdsclient/requests_counter.go +++ b/internal/xds/xdsclient/requests_counter.go @@ -81,27 +81,3 @@ func (c *ClusterRequestsCounter) StartRequest(max uint32) error { func (c *ClusterRequestsCounter) EndRequest() { atomic.AddUint32(&c.numRequests, ^uint32(0)) } - -// ClearCounterForTesting clears the counter for the service. Should be only -// used in tests. -func ClearCounterForTesting(clusterName, edsServiceName string) { - src.mu.Lock() - defer src.mu.Unlock() - k := clusterNameAndServiceName{ - clusterName: clusterName, - edsServiceName: edsServiceName, - } - c, ok := src.clusters[k] - if !ok { - return - } - c.numRequests = 0 -} - -// ClearAllCountersForTesting clears all the counters. Should be only used in -// tests. -func ClearAllCountersForTesting() { - src.mu.Lock() - defer src.mu.Unlock() - src.clusters = make(map[clusterNameAndServiceName]*ClusterRequestsCounter) -} -- 2.43.0