Skip to content

Commit

Permalink
ddl: reduce the time to run unit tests (pingcap#8585)
Browse files Browse the repository at this point in the history
  • Loading branch information
zimulala authored and jackysp committed Dec 14, 2018
1 parent 2088caf commit 4cbd501
Show file tree
Hide file tree
Showing 7 changed files with 455 additions and 406 deletions.
478 changes: 426 additions & 52 deletions ddl/db_integration_test.go

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions ddl/db_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1019,8 +1019,6 @@ func (s *testIntegrationSuite) TestPartitionCancelAddIndex(c *C) {
var checkErr error
var c3IdxInfo *model.IndexInfo
hook := &ddl.TestDDLCallback{}
oldReorgWaitTimeout := ddl.ReorgWaitTimeout
ddl.ReorgWaitTimeout = 10 * time.Millisecond
hook.OnJobUpdatedExported, c3IdxInfo, checkErr = backgroundExecOnJobUpdatedExported(c, s.store, s.ctx, hook)
s.dom.DDL().(ddl.DDLForTest).SetHook(hook)
done := make(chan error, 1)
Expand Down Expand Up @@ -1065,15 +1063,13 @@ LOOP:
checkDelRangeDone(c, s.ctx, idx)

tk.MustExec("drop table t1")
ddl.ReorgWaitTimeout = oldReorgWaitTimeout
callback := &ddl.TestDDLCallback{}
s.dom.DDL().(ddl.DDLForTest).SetHook(callback)
}

func backgroundExecOnJobUpdatedExported(c *C, store kv.Storage, ctx sessionctx.Context, hook *ddl.TestDDLCallback) (func(*model.Job), *model.IndexInfo, error) {
var checkErr error
first := true
ddl.ReorgWaitTimeout = 10 * time.Millisecond
c3IdxInfo := &model.IndexInfo{}
hook.OnJobUpdatedExported = func(job *model.Job) {
addIndexNotFirstReorg := job.Type == model.ActionAddIndex && job.SchemaState == model.StateWriteReorganization && job.SnapshotVer != 0
Expand Down
355 changes: 10 additions & 345 deletions ddl/db_test.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions ddl/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/meta"
"github.com/pingcap/tidb/meta/autoid"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/types"
Expand Down Expand Up @@ -100,6 +101,8 @@ func TestT(t *testing.T) {
Level: logLevel,
Format: "highlight",
})
autoid.SetStep(5000)
ReorgWaitTimeout = 30 * time.Millisecond
TestingT(t)
}

Expand Down
10 changes: 5 additions & 5 deletions ddl/ddl_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ const testLease = 5 * time.Millisecond

func (s *testDDLSuite) SetUpSuite(c *C) {
testleak.BeforeTest()
// set ReorgWaitTimeout to small value, make test to be faster.
ReorgWaitTimeout = 50 * time.Millisecond
WaitTimeWhenErrorOccured = 1 * time.Microsecond

// We hope that this test is serially executed. So put it here.
s.testRunWorker(c)
}

func (s *testDDLSuite) TearDownSuite(c *C) {
Expand All @@ -63,8 +64,8 @@ func (s *testDDLSuite) TestCheckOwner(c *C) {
c.Assert(d1.GetLease(), Equals, testLease)
}

// TestRunWorker tests no job is handled when the value of RunWorker is false.
func (s *testDDLSuite) TestRunWorker(c *C) {
// testRunWorker tests no job is handled when the value of RunWorker is false.
func (s *testDDLSuite) testRunWorker(c *C) {
store := testCreateStore(c, "test_run_worker")
defer store.Close()

Expand Down Expand Up @@ -784,7 +785,6 @@ func (s *testDDLSuite) TestDDLPackageExecuteSQL(c *C) {
store := testCreateStore(c, "test_run_sql")
defer store.Close()

RunWorker = true
d := testNewDDL(context.Background(), nil, store, nil, nil, testLease)
testCheckOwner(c, d, true)
defer d.Stop()
Expand Down
5 changes: 5 additions & 0 deletions ddl/failtest/fail_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ func (s *testFailDBSuite) TestFailSchemaSyncer(c *C) {
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int)")
defer tk.MustExec("drop table if exists t")
originalRetryTimes := domain.SchemaOutOfDateRetryTimes
domain.SchemaOutOfDateRetryTimes = 1
defer func() {
domain.SchemaOutOfDateRetryTimes = originalRetryTimes
}()
c.Assert(s.dom.SchemaValidator.IsStarted(), IsTrue)
mockSyncer, ok := s.dom.DDL().SchemaSyncer().(*ddl.MockSchemaSyncer)
c.Assert(ok, IsTrue)
Expand Down
6 changes: 6 additions & 0 deletions sessionctx/variable/statusvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ package variable
import (
"bytes"
"crypto/tls"
"sync"

"github.com/pingcap/errors"
)

var statisticsList []Statistics
var statisticsListLock sync.RWMutex

// DefaultStatusVarScopeFlag is the default scope of status variables.
var DefaultStatusVarScopeFlag = ScopeGlobal | ScopeSession
Expand All @@ -41,13 +43,17 @@ type Statistics interface {

// RegisterStatistics registers statistics.
func RegisterStatistics(s Statistics) {
statisticsListLock.Lock()
statisticsList = append(statisticsList, s)
statisticsListLock.Unlock()
}

// GetStatusVars gets registered statistics status variables.
// TODO: Refactor this function to avoid repeated memory allocation / dealloc
func GetStatusVars(vars *SessionVars) (map[string]*StatusVal, error) {
statusVars := make(map[string]*StatusVal)
statisticsListLock.RLock()
defer statisticsListLock.RUnlock()

for _, statistics := range statisticsList {
vals, err := statistics.Stats(vars)
Expand Down

0 comments on commit 4cbd501

Please sign in to comment.