Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools/ut: replace integration test in ci #8200

Merged
merged 4 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ failpoint-disable: install-tools

ut: pd-ut
@$(FAILPOINT_ENABLE)
./bin/pd-ut run --race
# only run unit tests
./bin/pd-ut run --ignore tests --race
@$(CLEAN_UT_BINARY)
@$(FAILPOINT_DISABLE)

Expand Down
13 changes: 7 additions & 6 deletions scripts/ci-subtask.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,28 @@ integrations_dir=$(pwd)/tests/integrations
case $1 in
1)
# unit tests ignore `tests`
./bin/pd-ut run --race --ignore tests --coverprofile $ROOT_PATH_COV || exit 1
./bin/pd-ut run --race --ignore tests --coverprofile $ROOT_PATH_COV || exit 1
;;
2)
# unit tests only in `tests`
./bin/pd-ut run tests --race --coverprofile $ROOT_PATH_COV || exit 1
./bin/pd-ut run tests --race --coverprofile $ROOT_PATH_COV || exit 1
;;
3)
# tools tests
cd ./tools && make ci-test-job && cat covprofile >> $ROOT_PATH_COV || exit 1
;;
4)
# integration test client
cd ./client && make ci-test-job && cat covprofile >> $ROOT_PATH_COV || exit 1
cd $integrations_dir && make ci-test-job test_name=client && cat ./client/covprofile >> $ROOT_PATH_COV || exit 1
./bin/pd-ut it run client --race --coverprofile $ROOT_PATH_COV || exit 1
# client tests
cd ./client && make ci-test-job && cat covprofile >> $ROOT_PATH_COV || exit 1
;;
5)
# integration test tso
cd $integrations_dir && make ci-test-job test_name=tso && cat ./tso/covprofile >> $ROOT_PATH_COV || exit 1
./bin/pd-ut it run tso --race --coverprofile $ROOT_PATH_COV || exit 1
;;
6)
# integration test mcs
cd $integrations_dir && make ci-test-job test_name=mcs && cat ./mcs/covprofile >> $ROOT_PATH_COV || exit 1
./bin/pd-ut it run mcs --race --coverprofile $ROOT_PATH_COV || exit 1
;;
esac
31 changes: 29 additions & 2 deletions tools/pd-ut/ut.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ go tool cover --func=xxx`
return true
}

const modulePath = "github.com/tikv/pd"
var (
modulePath = "github.com/tikv/pd"
integrationsTestPath = "tests/integrations"
)

var (
// runtime
Expand Down Expand Up @@ -139,6 +142,18 @@ func main() {
isSucceed = cmdBuild(os.Args[2:]...)
case "run":
isSucceed = cmdRun(os.Args[2:]...)
case "it":
// run integration tests
if len(os.Args) >= 3 {
modulePath = path.Join(modulePath, integrationsTestPath)
workDir = path.Join(workDir, integrationsTestPath)
switch os.Args[2] {
case "run":
isSucceed = cmdRun(os.Args[3:]...)
default:
isSucceed = usage()
}
}
default:
isSucceed = usage()
}
Expand Down Expand Up @@ -628,7 +643,7 @@ func (*numa) testCommand(pkg string, fn string) *exec.Cmd {
}

func skipDIR(pkg string) bool {
skipDir := []string{"bin", "cmd", "realcluster", "tests/integrations"}
skipDir := []string{"bin", "cmd", "realcluster"}
if ignoreDir != "" {
skipDir = append(skipDir, ignoreDir)
}
Expand All @@ -645,6 +660,11 @@ func generateBuildCache() error {
cmd := exec.Command("go", "test", "-exec=true", "-vet", "off", "--tags=tso_function_test,deadlock")
goCompileWithoutLink := fmt.Sprintf("-toolexec=%s/tools/pd-ut/go-compile-without-link.sh", workDir)
cmd.Dir = fmt.Sprintf("%s/cmd/pd-server", workDir)
if strings.Contains(workDir, integrationsTestPath) {
cmd.Dir = fmt.Sprintf("%s/cmd/pd-server", workDir[:strings.LastIndex(workDir, integrationsTestPath)])
goCompileWithoutLink = fmt.Sprintf("-toolexec=%s/tools/pd-ut/go-compile-without-link.sh",
workDir[:strings.LastIndex(workDir, integrationsTestPath)])
}
cmd.Args = append(cmd.Args, goCompileWithoutLink)

cmd.Stdout = os.Stdout
Expand All @@ -664,7 +684,11 @@ func buildTestBinaryMulti(pkgs []string) error {
}

// go test --exec=xprog --tags=tso_function_test,deadlock -vet=off --count=0 $(pkgs)
// workPath just like `/data/nvme0n1/husharp/proj/pd/tests/integrations`
xprogPath := path.Join(workDir, "bin/xprog")
if strings.Contains(workDir, integrationsTestPath) {
xprogPath = path.Join(workDir[:strings.LastIndex(workDir, integrationsTestPath)], "bin/xprog")
}
packages := make([]string, 0, len(pkgs))
for _, pkg := range pkgs {
packages = append(packages, path.Join(modulePath, pkg))
Expand All @@ -674,6 +698,9 @@ func buildTestBinaryMulti(pkgs []string) error {
cmd := exec.Command("go", "test", "-p", p, "--exec", xprogPath, "-vet", "off", "--tags=tso_function_test,deadlock")
if coverProfile != "" {
coverpkg := "./..."
if strings.Contains(workDir, integrationsTestPath) {
coverpkg = "../../..."
}
cmd.Args = append(cmd.Args, "-cover", fmt.Sprintf("-coverpkg=%s", coverpkg))
}
cmd.Args = append(cmd.Args, packages...)
Expand Down