From 1fbadf80085bcaefaa886a6649f26dccaa5851cd Mon Sep 17 00:00:00 2001 From: lhy1024 Date: Fri, 11 Oct 2019 10:12:04 +0800 Subject: [PATCH] test: repair test (#1792) Signed-off-by: lhy1024 --- server/coordinator_test.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/server/coordinator_test.go b/server/coordinator_test.go index 56fe9894acaa..218815397dfd 100644 --- a/server/coordinator_test.go +++ b/server/coordinator_test.go @@ -786,8 +786,10 @@ func (s *testOperatorControllerSuite) TestOperatorCount(c *C) { } func (s *testOperatorControllerSuite) TestStoreOverloaded(c *C) { - _, opt, err := newTestScheduleConfig() + cfg, opt, err := newTestScheduleConfig() + c.Assert(cfg, NotNil) c.Assert(err, IsNil) + cfg.StoreBalanceRate = 10 tc := newTestCluster(opt) hbStreams, cleanup := getHeartBeatStreams(c, tc) defer cleanup() @@ -801,22 +803,28 @@ func (s *testOperatorControllerSuite) TestStoreOverloaded(c *C) { c.Assert(tc.addRegionStore(2, 40), IsNil) c.Assert(tc.addRegionStore(1, 10), IsNil) c.Assert(tc.addLeaderRegion(1, 2, 3, 4), IsNil) + start := time.Now() op1 := lb.Schedule(tc)[0] c.Assert(op1, NotNil) c.Assert(oc.AddOperator(op1), IsTrue) for i := 0; i < 10; i++ { + if time.Now().Sub(start) >= time.Second*9/10 { + break + } c.Assert(lb.Schedule(tc), IsNil) } c.Assert(oc.RemoveOperator(op1), IsTrue) - time.Sleep(1 * time.Second) + time.Sleep(2 * time.Second) for i := 0; i < 100; i++ { c.Assert(lb.Schedule(tc), NotNil) } } func (s *testOperatorControllerSuite) TestStoreOverloadedWithReplace(c *C) { - _, opt, err := newTestScheduleConfig() + cfg, opt, err := newTestScheduleConfig() + c.Assert(cfg, NotNil) c.Assert(err, IsNil) + cfg.StoreBalanceRate = 10 tc := newTestCluster(opt) hbStreams, cleanup := getHeartBeatStreams(c, tc) defer cleanup() @@ -839,7 +847,7 @@ func (s *testOperatorControllerSuite) TestStoreOverloadedWithReplace(c *C) { op3 := newTestOperator(1, tc.GetRegion(2).GetRegionEpoch(), operator.OpRegion, operator.AddPeer{ToStore: 1, PeerID: 3}) c.Assert(oc.AddOperator(op3), IsFalse) c.Assert(lb.Schedule(tc), IsNil) - time.Sleep(1 * time.Second) + time.Sleep(2 * time.Second) c.Assert(lb.Schedule(tc), NotNil) }