Skip to content

Commit

Permalink
tools/check: fix timeout check script for parsing new tests (#26723)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored Aug 2, 2021
1 parent 92c8dcd commit e199323
Showing 1 changed file with 77 additions and 30 deletions.
107 changes: 77 additions & 30 deletions tools/check/check-timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bufio"
"errors"
"fmt"
"os"
"strings"
Expand All @@ -12,6 +13,8 @@ var allowList = make(map[string]struct{})

func init() {
tmp := []string{
"TestT",
"TestCluster",
"testIntegrationSuite4.TestAddPartitionTooManyPartitions",
"testIntegrationSuite5.TestBackwardCompatibility",
"testIntegrationSuite1.TestDisableTablePartition",
Expand Down Expand Up @@ -101,50 +104,94 @@ func init() {
}
}

func inAllowList(input string) bool {
// The input looks like this.
// PASS: sysvar_test.go:131: testSysVarSuite.TestIntValidation
offset := strings.LastIndexByte(input, ' ')
if offset < 0 {
return false
}
testName := input[offset+1:]
func inAllowList(testName string) bool {
_, ok := allowList[testName]
return ok
}

func main() {
lines := make([]string, 0, 100)
// The input looks like that:
func parseLine(line string) (testName string, dur time.Duration, err error) {
// The line looks like that:
// PASS: sysvar_test.go:131: testSysVarSuite.TestIntValidation 0.000s
// PASS: sysvar_test.go:454: testSysVarSuite.TestIsNoop 0.000s
// PASS: sysvar_test.go:302: testSysVarSuite.TestMaxExecutionTime 0.000s
// PASS: sysvar_test.go:429: testSysVarSuite.TestReadOnlyNoop 0.000s
// PASS: sysvar_test.go:97: testSysVarSuite.TestRegistrationOfNewSysVar 0.000s
// PASS: sysvar_test.go:269: testSysVarSuite.TestSQLModeVar 0.000s
// PASS: sysvar_test.go:254: testSysVarSuite.TestSQLSelectLimit 0.000s
// PASS: sysvar_test.go:224: testSysVarSuite.TestScope 0.000s
// PASS: sysvar_test.go:439: testSysVarSuite.TestSkipInit 0.000s
//
// They are generated by "grep '^:PASS' gotest.log", and gotest.log is generated by
// --- PASS: TestSingle (0.26s)
// --- PASS: TestCluster (4.20s)

line = strings.TrimSpace(line)

// Format type 1
if strings.HasPrefix(line, "PASS") {
return parseFormat1(line)
}

// Format type 2
if strings.HasPrefix(line, "---") {
return parseFormat2(line)
}

err = errors.New("unknown format: " + line)
return
}

func parseFormat1(line string) (testName string, dur time.Duration, err error) {
offset := strings.LastIndexByte(line, '\t')
if offset < 0 {
err = fmt.Errorf("get duration string error: %s", line)
return
}
durStr := line[offset+1:]
dur, err = time.ParseDuration(durStr)
if err != nil {
err = fmt.Errorf("parse duration string error: %s, %v", line, err)
return
}

offset1 := strings.LastIndexByte(line[:offset], ' ')
if offset1 < 0 {
err = errors.New("parse line error: " + line)
return
}
testName = line[offset1+1 : offset]
return
}

func parseFormat2(line string) (testName string, dur time.Duration, err error) {
offset := strings.LastIndexByte(line, ' ')
if offset < 0 {
err = fmt.Errorf("get duration string error: %s", line)
return
}
durStr := line[offset+2 : len(line)-1]
dur, err = time.ParseDuration(durStr)
if err != nil {
err = fmt.Errorf("parse duration string error: %s, %v", line, err)
return
}

offset1 := strings.LastIndexByte(line[:offset], ' ')
if offset1 < 0 {
err = errors.New("parse line err: " + line)
return
}
testName = line[offset1+1 : offset]
return
}

func main() {
lines := make([]string, 0, 100)
// They are generated by "grep 'PASS:' gotest.log", and gotest.log is generated by
// 'make gotest' from the Makefile which runs 'go test -v ./...' alike
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
line := scanner.Text()
offset := strings.LastIndexByte(line, '\t')
if offset < 0 {
fmt.Println("get duration string error:", line)
os.Exit(-1)
}
durStr := line[offset+1:]
dur, err := time.ParseDuration(durStr)
testName, dur, err := parseLine(line)
if err != nil {
fmt.Println("parse duration string error:", line, err)
os.Exit(-2)
fmt.Println("parser line error:", err)
os.Exit(-1)
}

if dur > 4*time.Second {
if inAllowList(line[:offset]) {
if dur > 5*time.Second {
if inAllowList(testName) {
continue
}
lines = append(lines, line)
Expand Down

0 comments on commit e199323

Please sign in to comment.