Skip to content

Commit

Permalink
gcworker: let gofail in gcworker run serially, make ci happy (pingcap…
Browse files Browse the repository at this point in the history
  • Loading branch information
winkyao authored and zz-jason committed Jan 4, 2019
1 parent e646276 commit 6d098d4
Showing 1 changed file with 53 additions and 23 deletions.
76 changes: 53 additions & 23 deletions store/tikv/gcworker/gc_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type testGCWorkerSuite struct {
}

var _ = Suite(&testGCWorkerSuite{})
var _ = SerialSuites(&testGCWorkerSerialSuite{})

func (s *testGCWorkerSuite) SetUpTest(c *C) {
tikv.NewGCHandlerFunc = NewGCWorker
Expand Down Expand Up @@ -160,7 +161,58 @@ func (s *testGCWorkerSuite) TestPrepareGC(c *C) {
c.Assert(ok, IsTrue)
}

func (s *testGCWorkerSuite) TestDoGCForOneRegion(c *C) {
func (s *testGCWorkerSuite) TestDoGC(c *C) {
var err error
ctx := context.Background()

gcSafePointCacheInterval = 1

err = s.gcWorker.saveValueToSysTable(gcConcurrencyKey, strconv.Itoa(gcDefaultConcurrency))
c.Assert(err, IsNil)
err = s.gcWorker.doGC(ctx, 20)
c.Assert(err, IsNil)

err = s.gcWorker.saveValueToSysTable(gcConcurrencyKey, strconv.Itoa(gcMinConcurrency))
c.Assert(err, IsNil)
err = s.gcWorker.doGC(ctx, 20)
c.Assert(err, IsNil)

err = s.gcWorker.saveValueToSysTable(gcConcurrencyKey, strconv.Itoa(gcMaxConcurrency))
c.Assert(err, IsNil)
err = s.gcWorker.doGC(ctx, 20)
c.Assert(err, IsNil)
}

type testGCWorkerSerialSuite struct {
store tikv.Storage
oracle *mockoracle.MockOracle
gcWorker *GCWorker
dom *domain.Domain
}

func (s *testGCWorkerSerialSuite) SetUpTest(c *C) {
tikv.NewGCHandlerFunc = NewGCWorker
store, err := mockstore.NewMockTikvStore()
s.store = store.(tikv.Storage)
c.Assert(err, IsNil)
s.oracle = &mockoracle.MockOracle{}
s.store.SetOracle(s.oracle)
s.dom, err = session.BootstrapSession(s.store)
c.Assert(err, IsNil)
gcWorker, err := NewGCWorker(s.store, nil)
c.Assert(err, IsNil)
gcWorker.Start()
gcWorker.Close()
s.gcWorker = gcWorker.(*GCWorker)
}

func (s *testGCWorkerSerialSuite) TearDownTest(c *C) {
s.dom.Close()
err := s.store.Close()
c.Assert(err, IsNil)
}

func (s *testGCWorkerSerialSuite) TestDoGCForOneRegion(c *C) {
var successRegions int32
var failedRegions int32
taskWorker := newGCTaskWorker(s.store, nil, nil, s.gcWorker.uuid, &successRegions, &failedRegions)
Expand Down Expand Up @@ -192,25 +244,3 @@ func (s *testGCWorkerSuite) TestDoGCForOneRegion(c *C) {
c.Assert(err, IsNil)
gofail.Disable("github.com/pingcap/tidb/store/tikv/tikvStoreSendReqResult")
}

func (s *testGCWorkerSuite) TestDoGC(c *C) {
var err error
ctx := context.Background()

gcSafePointCacheInterval = 1

err = s.gcWorker.saveValueToSysTable(gcConcurrencyKey, strconv.Itoa(gcDefaultConcurrency))
c.Assert(err, IsNil)
err = s.gcWorker.doGC(ctx, 20)
c.Assert(err, IsNil)

err = s.gcWorker.saveValueToSysTable(gcConcurrencyKey, strconv.Itoa(gcMinConcurrency))
c.Assert(err, IsNil)
err = s.gcWorker.doGC(ctx, 20)
c.Assert(err, IsNil)

err = s.gcWorker.saveValueToSysTable(gcConcurrencyKey, strconv.Itoa(gcMaxConcurrency))
c.Assert(err, IsNil)
err = s.gcWorker.doGC(ctx, 20)
c.Assert(err, IsNil)
}

0 comments on commit 6d098d4

Please sign in to comment.