From 60a3a7e969c401ca16dbcd0108ad544fb35aa61c Mon Sep 17 00:00:00 2001 From: Easwar Swaminathan Date: Fri, 2 Sep 2022 14:09:10 -0700 Subject: [PATCH] cleanup: fixes for issues surfaced by vet (#5617) --- balancer/rls/balancer_test.go | 4 +--- credentials/alts/internal/conn/record_test.go | 4 ++-- internal/testutils/balancer.go | 5 +---- internal/testutils/roundrobin/roundrobin.go | 2 +- xds/internal/balancer/clusterimpl/balancer_test.go | 7 ------- xds/internal/balancer/priority/balancer_test.go | 10 ---------- 6 files changed, 5 insertions(+), 27 deletions(-) diff --git a/balancer/rls/balancer_test.go b/balancer/rls/balancer_test.go index 7df7f4335..6ac57188b 100644 --- a/balancer/rls/balancer_test.go +++ b/balancer/rls/balancer_test.go @@ -886,9 +886,7 @@ func (w *wrappingTopLevelBalancer) getStates() []balancer.State { defer w.mu.Unlock() states := make([]balancer.State, len(w.states)) - for i, s := range w.states { - states[i] = s - } + copy(states, w.states) return states } diff --git a/credentials/alts/internal/conn/record_test.go b/credentials/alts/internal/conn/record_test.go index c18f902b4..0b4177a58 100644 --- a/credentials/alts/internal/conn/record_test.go +++ b/credentials/alts/internal/conn/record_test.go @@ -220,7 +220,7 @@ func testFrameTooLarge(t *testing.T, rp string) { payload := make([]byte, payloadLen) c, err := clientConn.crypto.Encrypt(nil, payload) if err != nil { - t.Fatalf(fmt.Sprintf("Error encrypting message: %v", err)) + t.Fatalf("Error encrypting message: %v", err) } msgLen := msgTypeFieldSize + len(c) framedMsg := make([]byte, MsgLenFieldSize+msgLen) @@ -229,7 +229,7 @@ func testFrameTooLarge(t *testing.T, rp string) { binary.LittleEndian.PutUint32(msg[:msgTypeFieldSize], altsRecordMsgType) copy(msg[msgTypeFieldSize:], c) if _, err = buf.Write(framedMsg); err != nil { - t.Fatal(fmt.Sprintf("Unexpected error writing to buffer: %v", err)) + t.Fatalf("Unexpected error writing to buffer: %v", err) } b := make([]byte, 1) if n, err := serverConn.Read(b); n != 0 || err == nil { diff --git a/internal/testutils/balancer.go b/internal/testutils/balancer.go index f23b215a7..5983d75ba 100644 --- a/internal/testutils/balancer.go +++ b/internal/testutils/balancer.go @@ -198,10 +198,7 @@ func (tcc *TestClientConn) WaitForPickerWithErr(ctx context.Context, want error) case <-ctx.Done(): return fmt.Errorf("timeout when waiting for an error picker with %v; last picker error: %v", want, lastErr) case picker := <-tcc.NewPickerCh: - for i := 0; i < 5; i++ { - if _, lastErr = picker.Pick(balancer.PickInfo{}); lastErr == nil || lastErr.Error() != want.Error() { - break - } + if _, lastErr = picker.Pick(balancer.PickInfo{}); lastErr != nil && lastErr.Error() == want.Error() { return nil } } diff --git a/internal/testutils/roundrobin/roundrobin.go b/internal/testutils/roundrobin/roundrobin.go index 8c4b4e4bd..8f9e79b50 100644 --- a/internal/testutils/roundrobin/roundrobin.go +++ b/internal/testutils/roundrobin/roundrobin.go @@ -127,7 +127,7 @@ func CheckRoundRobinRPCs(ctx context.Context, client testgrpc.TestServiceClient, } return nil } - return fmt.Errorf("Timeout when waiting for roundrobin distribution of RPCs across addresses: %v", addrs) + return fmt.Errorf("timeout when waiting for roundrobin distribution of RPCs across addresses: %v", addrs) } // CheckWeightedRoundRobinRPCs verifies that EmptyCall RPCs on the given diff --git a/xds/internal/balancer/clusterimpl/balancer_test.go b/xds/internal/balancer/clusterimpl/balancer_test.go index a0085872a..1d531c1a5 100644 --- a/xds/internal/balancer/clusterimpl/balancer_test.go +++ b/xds/internal/balancer/clusterimpl/balancer_test.go @@ -76,13 +76,6 @@ func Test(t *testing.T) { grpctest.RunSubTests(t, s{}) } -func subConnFromPicker(p balancer.Picker) func() balancer.SubConn { - return func() balancer.SubConn { - scst, _ := p.Pick(balancer.PickInfo{}) - return scst.SubConn - } -} - func init() { NewRandomWRR = testutils.NewTestWRR } diff --git a/xds/internal/balancer/priority/balancer_test.go b/xds/internal/balancer/priority/balancer_test.go index d3329378c..d119076d1 100644 --- a/xds/internal/balancer/priority/balancer_test.go +++ b/xds/internal/balancer/priority/balancer_test.go @@ -70,16 +70,6 @@ func init() { balancer.Register(&anotherRR{Builder: balancer.Get(roundrobin.Name)}) } -func subConnFromPicker(t *testing.T, p balancer.Picker) func() balancer.SubConn { - return func() balancer.SubConn { - scst, err := p.Pick(balancer.PickInfo{}) - if err != nil { - t.Fatalf("unexpected error from picker.Pick: %v", err) - } - return scst.SubConn - } -} - // When a high priority is ready, adding/removing lower locality doesn't cause // changes. //