From 7f6d801a578cc34644abdbdb627cbfed054ff342 Mon Sep 17 00:00:00 2001 From: Lynn Date: Thu, 20 Apr 2017 14:16:32 +0800 Subject: [PATCH] ddl: make test stable (#3091) --- ddl/reorg_test.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/ddl/reorg_test.go b/ddl/reorg_test.go index 6dc600f054..7b8c1334f0 100644 --- a/ddl/reorg_test.go +++ b/ddl/reorg_test.go @@ -60,25 +60,27 @@ func (s *testDDLSuite) TestReorg(c *C) { err = ctx.Txn().Commit() c.Assert(err, IsNil) - done := make(chan struct{}) rowCount := int64(10) f := func() error { d.setReorgRowCount(rowCount) time.Sleep(4 * testLease) - close(done) return nil } job := &model.Job{} err = d.runReorgJob(job, f) c.Assert(err, NotNil) - <-done - // Make sure the function of f is returned. - time.Sleep(5 * time.Millisecond) - err = d.runReorgJob(job, f) + // The longest to wait for 5 seconds to make sure the function of f is returned. + for i := 0; i < 1000; i++ { + time.Sleep(5 * time.Millisecond) + err = d.runReorgJob(job, f) + if err == nil { + c.Assert(job.RowCount, Equals, rowCount) + c.Assert(d.reorgRowCount, Equals, int64(0)) + break + } + } c.Assert(err, IsNil) - c.Assert(job.RowCount, Equals, rowCount) - c.Assert(d.reorgRowCount, Equals, int64(0)) d.Stop() err = d.runReorgJob(job, func() error {