From 170b4984c6dc1405feccac7460f89b6c6d1d0da6 Mon Sep 17 00:00:00 2001 From: lhy1024 Date: Wed, 22 Jun 2022 17:30:37 +0800 Subject: [PATCH] *: some misc modify for testify (#5211) ref tikv/pd#4813, ref tikv/pd#5193 Signed-off-by: lhy1024 Co-authored-by: Ti Chi Robot --- pkg/errs/errs_test.go | 2 +- pkg/movingaverage/moving_average_test.go | 4 +-- .../checker/joint_state_checker_test.go | 4 +-- .../checker/priority_inspector_test.go | 4 +-- server/schedule/placement/rule_test.go | 2 +- tests/client/client_test.go | 28 +++++++++---------- tests/pdctl/config/config_test.go | 4 +-- tests/server/tso/manager_test.go | 2 +- tools/pd-ctl/pdctl/ctl_test.go | 2 +- 9 files changed, 26 insertions(+), 26 deletions(-) diff --git a/pkg/errs/errs_test.go b/pkg/errs/errs_test.go index 4556898d9fd..591d9f899ce 100644 --- a/pkg/errs/errs_test.go +++ b/pkg/errs/errs_test.go @@ -141,5 +141,5 @@ func TestErrorWithStack(t *testing.T) { re.GreaterOrEqual(idx1, -1) idx2 := strings.Index(m2, "[stack=") re.GreaterOrEqual(idx2, -1) - re.Equal(len(m1[idx1:]), len(m2[idx2:])) + re.Len(m2[idx2:], len(m1[idx1:])) } diff --git a/pkg/movingaverage/moving_average_test.go b/pkg/movingaverage/moving_average_test.go index 9f6864b007b..173eea773bb 100644 --- a/pkg/movingaverage/moving_average_test.go +++ b/pkg/movingaverage/moving_average_test.go @@ -40,7 +40,7 @@ func checkReset(re *require.Assertions, ma MovingAvg, emptyValue float64) { // checkAddGet checks Add works properly. func checkAdd(re *require.Assertions, ma MovingAvg, data []float64, expected []float64) { - re.Equal(len(expected), len(data)) + re.Len(data, len(expected)) for i, x := range data { ma.Add(x) re.LessOrEqual(math.Abs(ma.Get()-expected[i]), 1e-7) @@ -49,7 +49,7 @@ func checkAdd(re *require.Assertions, ma MovingAvg, data []float64, expected []f // checkSet checks Set = Reset + Add func checkSet(re *require.Assertions, ma MovingAvg, data []float64, expected []float64) { - re.Equal(len(expected), len(data)) + re.Len(data, len(expected)) // Reset + Add addRandData(ma, 100, 1000) diff --git a/server/schedule/checker/joint_state_checker_test.go b/server/schedule/checker/joint_state_checker_test.go index b350de469c4..e2986ae11ee 100644 --- a/server/schedule/checker/joint_state_checker_test.go +++ b/server/schedule/checker/joint_state_checker_test.go @@ -132,8 +132,8 @@ func checkSteps(re *require.Assertions, op *operator.Operator, steps []operator. switch obtain := op.Step(i).(type) { case operator.ChangePeerV2Leave: expect := steps[i].(operator.ChangePeerV2Leave) - re.Equal(len(expect.PromoteLearners), len(obtain.PromoteLearners)) - re.Equal(len(expect.DemoteVoters), len(obtain.DemoteVoters)) + re.Len(obtain.PromoteLearners, len(expect.PromoteLearners)) + re.Len(obtain.DemoteVoters, len(expect.DemoteVoters)) for j, p := range expect.PromoteLearners { re.Equal(p.ToStore, obtain.PromoteLearners[j].ToStore) } diff --git a/server/schedule/checker/priority_inspector_test.go b/server/schedule/checker/priority_inspector_test.go index 35662846c4a..9e0b0264a45 100644 --- a/server/schedule/checker/priority_inspector_test.go +++ b/server/schedule/checker/priority_inspector_test.go @@ -56,7 +56,7 @@ func checkPriorityRegionTest(re *require.Assertions, pc *PriorityInspector, tc * pc.Inspect(region) re.Equal(1, pc.queue.Len()) // the region will not rerun after it checks - re.Equal(0, len(pc.GetPriorityRegions())) + re.Len(pc.GetPriorityRegions(), 0) // case3: inspect region 3, it will has high priority region = tc.GetRegion(3) @@ -65,7 +65,7 @@ func checkPriorityRegionTest(re *require.Assertions, pc *PriorityInspector, tc * time.Sleep(opt.GetPatrolRegionInterval() * 10) // region 3 has higher priority ids := pc.GetPriorityRegions() - re.Equal(2, len(ids)) + re.Len(ids, 2) re.Equal(uint64(3), ids[0]) re.Equal(uint64(2), ids[1]) diff --git a/server/schedule/placement/rule_test.go b/server/schedule/placement/rule_test.go index ba2d1bf50e4..52d25c82e03 100644 --- a/server/schedule/placement/rule_test.go +++ b/server/schedule/placement/rule_test.go @@ -54,7 +54,7 @@ func TestPrepareRulesForApply(t *testing.T) { sortRules(rules) rules = prepareRulesForApply(rules) - re.Equal(len(expected), len(rules)) + re.Len(rules, len(expected)) for i := range rules { re.Equal(expected[i], rules[i].Key()) } diff --git a/tests/client/client_test.go b/tests/client/client_test.go index a9022d04a20..c6c4f45ee47 100644 --- a/tests/client/client_test.go +++ b/tests/client/client_test.go @@ -192,11 +192,11 @@ func TestUpdateAfterResetTSO(t *testing.T) { return err == nil }) // Transfer leader to trigger the TSO resetting. - re.Nil(failpoint.Enable("github.com/tikv/pd/server/updateAfterResetTSO", "return(true)")) + re.NoError(failpoint.Enable("github.com/tikv/pd/server/updateAfterResetTSO", "return(true)")) oldLeaderName := cluster.WaitLeader() err = cluster.GetServer(oldLeaderName).ResignLeader() re.NoError(err) - re.Nil(failpoint.Disable("github.com/tikv/pd/server/updateAfterResetTSO")) + re.NoError(failpoint.Disable("github.com/tikv/pd/server/updateAfterResetTSO")) newLeaderName := cluster.WaitLeader() re.NotEqual(oldLeaderName, newLeaderName) // Request a new TSO. @@ -205,7 +205,7 @@ func TestUpdateAfterResetTSO(t *testing.T) { return err == nil }) // Transfer leader back. - re.Nil(failpoint.Enable("github.com/tikv/pd/server/tso/delaySyncTimestamp", `return(true)`)) + re.NoError(failpoint.Enable("github.com/tikv/pd/server/tso/delaySyncTimestamp", `return(true)`)) err = cluster.GetServer(newLeaderName).ResignLeader() re.NoError(err) // Should NOT panic here. @@ -213,7 +213,7 @@ func TestUpdateAfterResetTSO(t *testing.T) { _, _, err := cli.GetTS(context.TODO()) return err == nil }) - re.Nil(failpoint.Disable("github.com/tikv/pd/server/tso/delaySyncTimestamp")) + re.NoError(failpoint.Disable("github.com/tikv/pd/server/tso/delaySyncTimestamp")) } func TestTSOAllocatorLeader(t *testing.T) { @@ -360,7 +360,7 @@ func TestGlobalAndLocalTSO(t *testing.T) { requestGlobalAndLocalTSO(re, wg, dcLocationConfig, cli) // assert global tso after resign leader - re.Nil(failpoint.Enable("github.com/tikv/pd/client/skipUpdateMember", `return(true)`)) + re.NoError(failpoint.Enable("github.com/tikv/pd/client/skipUpdateMember", `return(true)`)) err = cluster.ResignLeader() re.NoError(err) cluster.WaitLeader() @@ -369,7 +369,7 @@ func TestGlobalAndLocalTSO(t *testing.T) { re.True(pd.IsLeaderChange(err)) _, _, err = cli.GetTS(ctx) re.NoError(err) - re.Nil(failpoint.Disable("github.com/tikv/pd/client/skipUpdateMember")) + re.NoError(failpoint.Disable("github.com/tikv/pd/client/skipUpdateMember")) // Test the TSO follower proxy while enabling the Local TSO. cli.UpdateOption(pd.EnableTSOFollowerProxy, true) @@ -427,9 +427,9 @@ func TestCustomTimeout(t *testing.T) { cli := setupCli(re, ctx, endpoints, pd.WithCustomTimeoutOption(1*time.Second)) start := time.Now() - re.Nil(failpoint.Enable("github.com/tikv/pd/server/customTimeout", "return(true)")) + re.NoError(failpoint.Enable("github.com/tikv/pd/server/customTimeout", "return(true)")) _, err = cli.GetAllStores(context.TODO()) - re.Nil(failpoint.Disable("github.com/tikv/pd/server/customTimeout")) + re.NoError(failpoint.Disable("github.com/tikv/pd/server/customTimeout")) re.Error(err) re.GreaterOrEqual(time.Since(start), 1*time.Second) re.Less(time.Since(start), 2*time.Second) @@ -447,13 +447,13 @@ func TestGetRegionFromFollowerClient(t *testing.T) { endpoints := runServer(re, cluster) cli := setupCli(re, ctx, endpoints, pd.WithForwardingOption(true)) - re.Nil(failpoint.Enable("github.com/tikv/pd/client/unreachableNetwork1", "return(true)")) + re.NoError(failpoint.Enable("github.com/tikv/pd/client/unreachableNetwork1", "return(true)")) time.Sleep(200 * time.Millisecond) r, err := cli.GetRegion(context.Background(), []byte("a")) re.NoError(err) re.NotNil(r) - re.Nil(failpoint.Disable("github.com/tikv/pd/client/unreachableNetwork1")) + re.NoError(failpoint.Disable("github.com/tikv/pd/client/unreachableNetwork1")) time.Sleep(200 * time.Millisecond) r, err = cli.GetRegion(context.Background(), []byte("a")) re.NoError(err) @@ -473,7 +473,7 @@ func TestGetTsoFromFollowerClient1(t *testing.T) { endpoints := runServer(re, cluster) cli := setupCli(re, ctx, endpoints, pd.WithForwardingOption(true)) - re.Nil(failpoint.Enable("github.com/tikv/pd/client/unreachableNetwork", "return(true)")) + re.NoError(failpoint.Enable("github.com/tikv/pd/client/unreachableNetwork", "return(true)")) var lastTS uint64 testutil.Eventually(re, func() bool { physical, logical, err := cli.GetTS(context.TODO()) @@ -486,7 +486,7 @@ func TestGetTsoFromFollowerClient1(t *testing.T) { }) lastTS = checkTS(re, cli, lastTS) - re.Nil(failpoint.Disable("github.com/tikv/pd/client/unreachableNetwork")) + re.NoError(failpoint.Disable("github.com/tikv/pd/client/unreachableNetwork")) time.Sleep(2 * time.Second) checkTS(re, cli, lastTS) } @@ -504,7 +504,7 @@ func TestGetTsoFromFollowerClient2(t *testing.T) { endpoints := runServer(re, cluster) cli := setupCli(re, ctx, endpoints, pd.WithForwardingOption(true)) - re.Nil(failpoint.Enable("github.com/tikv/pd/client/unreachableNetwork", "return(true)")) + re.NoError(failpoint.Enable("github.com/tikv/pd/client/unreachableNetwork", "return(true)")) var lastTS uint64 testutil.Eventually(re, func() bool { physical, logical, err := cli.GetTS(context.TODO()) @@ -521,7 +521,7 @@ func TestGetTsoFromFollowerClient2(t *testing.T) { cluster.WaitLeader() lastTS = checkTS(re, cli, lastTS) - re.Nil(failpoint.Disable("github.com/tikv/pd/client/unreachableNetwork")) + re.NoError(failpoint.Disable("github.com/tikv/pd/client/unreachableNetwork")) time.Sleep(5 * time.Second) checkTS(re, cli, lastTS) } diff --git a/tests/pdctl/config/config_test.go b/tests/pdctl/config/config_test.go index f5acd3fd3ff..a0de13e30d6 100644 --- a/tests/pdctl/config/config_test.go +++ b/tests/pdctl/config/config_test.go @@ -761,7 +761,7 @@ func TestPDServerConfig(t *testing.T) { } func assertBundles(re *require.Assertions, a, b []placement.GroupBundle) { - re.Equal(len(a), len(b)) + re.Len(b, len(a)) for i := 0; i < len(a); i++ { assertBundle(re, a[i], b[i]) } @@ -771,7 +771,7 @@ func assertBundle(re *require.Assertions, a, b placement.GroupBundle) { re.Equal(a.ID, b.ID) re.Equal(a.Index, b.Index) re.Equal(a.Override, b.Override) - re.Equal(len(a.Rules), len(b.Rules)) + re.Len(b.Rules, len(a.Rules)) for i := 0; i < len(a.Rules); i++ { assertRule(re, a.Rules[i], b.Rules[i]) } diff --git a/tests/server/tso/manager_test.go b/tests/server/tso/manager_test.go index 5ea8bc4be92..00278544f55 100644 --- a/tests/server/tso/manager_test.go +++ b/tests/server/tso/manager_test.go @@ -130,7 +130,7 @@ func TestLocalTSOSuffix(t *testing.T) { clientv3.WithPrefix(), clientv3.WithSort(clientv3.SortByValue, clientv3.SortAscend)) re.NoError(err) - re.Equal(len(testCase.dcLocations), len(allSuffixResp.Kvs)) + re.Len(allSuffixResp.Kvs, len(testCase.dcLocations)) var lastSuffixNum int64 for _, kv := range allSuffixResp.Kvs { suffixNum, err := strconv.ParseInt(string(kv.Value), 10, 64) diff --git a/tools/pd-ctl/pdctl/ctl_test.go b/tools/pd-ctl/pdctl/ctl_test.go index 6dc29058e34..d9cea460e21 100644 --- a/tools/pd-ctl/pdctl/ctl_test.go +++ b/tools/pd-ctl/pdctl/ctl_test.go @@ -86,7 +86,7 @@ func TestReadStdin(t *testing.T) { for _, v := range s { in, err := ReadStdin(v.in) re.NoError(err) - re.Equal(len(v.targets), len(in)) + re.Len(in, len(v.targets)) for i, target := range v.targets { re.Equal(target, in[i]) }