Skip to content

Commit

Permalink
tools/check: 'ut' now remove support for the old test cases (#34800)
Browse files Browse the repository at this point in the history
close #30822
  • Loading branch information
tiancaiamao committed May 19, 2022
1 parent 37ba54e commit 098dee6
Showing 1 changed file with 7 additions and 45 deletions.
52 changes: 7 additions & 45 deletions tools/check/ut.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ const modulePath = "github.com/pingcap/tidb"
type task struct {
pkg string
test string
old bool
}

func (t *task) String() string {
Expand Down Expand Up @@ -626,17 +625,9 @@ func listTestCases(pkg string, tasks []task) ([]task, error) {
return nil, withTrace(err)
}
for _, c := range newCases {
tasks = append(tasks, task{pkg, c, false})
tasks = append(tasks, task{pkg, c})
}

oldCases, err := listOldTestCases(pkg)
if err != nil {
fmt.Println("list old test case error", pkg, err)
return nil, withTrace(err)
}
for _, c := range oldCases {
tasks = append(tasks, task{pkg, c, true})
}
return tasks, nil
}

Expand Down Expand Up @@ -692,7 +683,7 @@ type numa struct {
func (n *numa) worker(wg *sync.WaitGroup, ch chan task) {
defer wg.Done()
for t := range ch {
res := n.runTestCase(t.pkg, t.test, t.old)
res := n.runTestCase(t.pkg, t.test)
if res.Failure != nil {
fmt.Println("[FAIL] ", t.pkg, t.test)
fmt.Fprintf(os.Stderr, "err=%s\n%s", res.err.Error(), res.Failure.Contents)
Expand All @@ -708,7 +699,7 @@ type testResult struct {
err error
}

func (n *numa) runTestCase(pkg string, fn string, old bool) testResult {
func (n *numa) runTestCase(pkg string, fn string) testResult {
res := testResult{
JUnitTestCase: JUnitTestCase{
Classname: path.Join(modulePath, pkg),
Expand All @@ -720,7 +711,7 @@ func (n *numa) runTestCase(pkg string, fn string, old bool) testResult {
var err error
var start time.Time
for i := 0; i < 3; i++ {
cmd := n.testCommand(pkg, fn, old)
cmd := n.testCommand(pkg, fn)
cmd.Dir = path.Join(workDir, pkg)
// Combine the test case output, so the run result for failed cases can be displayed.
cmd.Stdout = &buf
Expand Down Expand Up @@ -805,7 +796,7 @@ func failureCases(input []JUnitTestCase) int {
return sum
}

func (n *numa) testCommand(pkg string, fn string, old bool) *exec.Cmd {
func (n *numa) testCommand(pkg string, fn string) *exec.Cmd {
args := make([]string, 0, 10)
exe := "./" + testFileName(pkg)
if coverprofile != "" {
Expand All @@ -818,13 +809,8 @@ func (n *numa) testCommand(pkg string, fn string, old bool) *exec.Cmd {
// Don't set timeout for race because it takes a longer when race is enabled.
args = append(args, []string{"-test.timeout", "2m"}...)
}
if old {
// session.test -test.run '^TestT$' -check.f testTxnStateSerialSuite.TestTxnInfoWithPSProtoco
args = append(args, "-test.run", "^TestT$", "-check.f", fn)
} else {
// session.test -test.run TestClusteredPrefixColum
args = append(args, "-test.run", fn)
}
// session.test -test.run TestClusteredPrefixColum
args = append(args, "-test.run", fn)

return exec.Command(exe, args...)
}
Expand Down Expand Up @@ -918,30 +904,6 @@ func listNewTestCases(pkg string) ([]string, error) {
}), nil
}

func listOldTestCases(pkg string) (res []string, err error) {
exe := "./" + testFileName(pkg)

// Maybe the restructure is finish on this package.
cmd := exec.Command(exe, "-h")
cmd.Dir = path.Join(workDir, pkg)
buf, err := cmd.CombinedOutput()
if err != nil {
err = withTrace(err)
return
}
if !bytes.Contains(buf, []byte("check.list")) {
// there is no old test case in pkg
return
}

// session.test -test.run TestT -check.list Test
cmd = exec.Command(exe, "-test.run", "^TestT$", "-check.list", "Test")
cmd.Dir = path.Join(workDir, pkg)
res, err = cmdToLines(cmd)
res = filter(res, func(s string) bool { return strings.Contains(s, "Test") })
return res, withTrace(err)
}

func cmdToLines(cmd *exec.Cmd) ([]string, error) {
res, err := cmd.Output()
if err != nil {
Expand Down

0 comments on commit 098dee6

Please sign in to comment.