Skip to content

Commit

Permalink
*: some misc modify for testify (tikv#5211)
Browse files Browse the repository at this point in the history
ref tikv#4813, ref tikv#5193

Signed-off-by: lhy1024 <[email protected]>

Co-authored-by: Ti Chi Robot <[email protected]>
  • Loading branch information
2 people authored and CabinfeverB committed Jul 14, 2022
1 parent c8ce97c commit 187e514
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion pkg/errs/errs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:]))
}
4 changes: 2 additions & 2 deletions pkg/movingaverage/moving_average_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions server/schedule/checker/joint_state_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions server/schedule/checker/priority_inspector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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])

Expand Down
2 changes: 1 addition & 1 deletion server/schedule/placement/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
28 changes: 14 additions & 14 deletions tests/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -205,15 +205,15 @@ 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.
testutil.Eventually(re, func() bool {
_, _, 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) {
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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())
Expand All @@ -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)
}
Expand All @@ -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())
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions tests/pdctl/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Expand All @@ -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])
}
Expand Down
2 changes: 1 addition & 1 deletion tests/server/tso/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tools/pd-ctl/pdctl/ctl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Expand Down

0 comments on commit 187e514

Please sign in to comment.