From fc71a95b9a40452a163beb176e543e23aff8415e Mon Sep 17 00:00:00 2001 From: lhy1024 Date: Wed, 30 Oct 2024 12:37:35 +0800 Subject: [PATCH] make test stable Signed-off-by: lhy1024 --- server/cluster/cluster_test.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/server/cluster/cluster_test.go b/server/cluster/cluster_test.go index fdba7349ca4a..15554716df19 100644 --- a/server/cluster/cluster_test.go +++ b/server/cluster/cluster_test.go @@ -2886,7 +2886,9 @@ func TestCheckCache(t *testing.T) { // case 1: operator cannot be created due to replica-schedule-limit restriction checker.PatrolRegions() - re.True(checker.IsPatrolRegionChanEmpty()) + testutil.Eventually(re, func() bool { + return checker.IsPatrolRegionChanEmpty() + }) re.Empty(oc.GetOperators()) re.Len(checker.GetPendingProcessedRegions(), 1) @@ -2895,7 +2897,9 @@ func TestCheckCache(t *testing.T) { cfg.ReplicaScheduleLimit = 10 tc.SetScheduleConfig(cfg) checker.PatrolRegions() - re.True(checker.IsPatrolRegionChanEmpty()) + testutil.Eventually(re, func() bool { + return checker.IsPatrolRegionChanEmpty() + }) re.Len(oc.GetOperators(), 1) re.Empty(checker.GetPendingProcessedRegions()) @@ -2903,14 +2907,18 @@ func TestCheckCache(t *testing.T) { oc.RemoveOperator(oc.GetOperator(1)) tc.SetStoreLimit(1, storelimit.AddPeer, 0) checker.PatrolRegions() - re.True(checker.IsPatrolRegionChanEmpty()) + testutil.Eventually(re, func() bool { + return checker.IsPatrolRegionChanEmpty() + }) re.Len(checker.GetPendingProcessedRegions(), 1) // cancel the store limit restriction tc.SetStoreLimit(1, storelimit.AddPeer, 10) time.Sleep(time.Second) checker.PatrolRegions() - re.True(checker.IsPatrolRegionChanEmpty()) + testutil.Eventually(re, func() bool { + return checker.IsPatrolRegionChanEmpty() + }) re.Len(oc.GetOperators(), 1) re.Empty(checker.GetPendingProcessedRegions()) @@ -2949,6 +2957,7 @@ func TestPatrolRegionConcurrency(t *testing.T) { re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/schedule/checker/breakPatrol", `return`)) checker.PatrolRegions() testutil.Eventually(re, func() bool { + fmt.Println(len(oc.GetOperators())) return len(oc.GetOperators()) >= mergeScheduleLimit }) checkOperatorDuplicate(re, oc.GetOperators())