Skip to content

Commit

Permalink
server: speed up unit test (pingcap#2010)
Browse files Browse the repository at this point in the history
run many test cases parallel
split databases in server package for parallel
  • Loading branch information
tiancaiamao authored Nov 23, 2016
1 parent 2432209 commit f4b78e4
Show file tree
Hide file tree
Showing 11 changed files with 862 additions and 233 deletions.
14 changes: 13 additions & 1 deletion _vendor/src/github.com/pingcap/check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type C struct {
logb *logger
logw io.Writer
done chan *C
parallel chan *C
reason string
mustFail bool
tempDir *tempDir
Expand Down Expand Up @@ -611,13 +612,23 @@ func (runner *suiteRunner) run() *Result {
if runner.checkFixtureArgs() {
c := runner.runFixture(runner.setUpSuite, "", nil)
if c == nil || c.status() == succeededSt {
var delayedC []*C
for i := 0; i != len(runner.tests); i++ {
c := runner.runTest(runner.tests[i])
c := runner.forkTest(runner.tests[i])
select {
case <-c.done:
case <-c.parallel:
delayedC = append(delayedC, c)
}
if c.status() == fixturePanickedSt {
runner.skipTests(missedSt, runner.tests[i+1:])
break
}
}
// Wait those parallel tests finish.
for _, delayed := range delayedC {
<-delayed.done
}
} else if c != nil && c.status() == skippedSt {
runner.skipTests(skippedSt, runner.tests)
} else {
Expand Down Expand Up @@ -655,6 +666,7 @@ func (runner *suiteRunner) forkCall(method *methodType, kind funcKind, testName
logw: logw,
tempDir: runner.tempDir,
done: make(chan *C, 1),
parallel: make(chan *C, 1),
timer: timer{benchTime: runner.benchTime},
startTime: time.Now(),
benchMem: runner.benchMem,
Expand Down
5 changes: 5 additions & 0 deletions _vendor/src/github.com/pingcap/check/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ func (c *C) Skip(reason string) {
c.stopNow()
}

// Parallel will mark the test run parallel within a test suite.
func (c *C) Parallel() {
c.parallel <- c
}

// -----------------------------------------------------------------------
// Basic logging.

Expand Down
Loading

0 comments on commit f4b78e4

Please sign in to comment.