From 2fabb74157938ced112b1d768cb8d4b995653275 Mon Sep 17 00:00:00 2001 From: Hu# Date: Tue, 21 May 2024 10:34:16 +0800 Subject: [PATCH] tools/ut: replace integration test in ci (#8200) ref tikv/pd#7969 Signed-off-by: husharp --- Makefile | 3 ++- scripts/ci-subtask.sh | 13 +++++++------ tools/pd-ut/ut.go | 31 +++++++++++++++++++++++++++++-- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 779cbd21efb..dca00012114 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/scripts/ci-subtask.sh b/scripts/ci-subtask.sh index c8ac823bf19..9bdce420d4a 100755 --- a/scripts/ci-subtask.sh +++ b/scripts/ci-subtask.sh @@ -9,11 +9,11 @@ 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 @@ -21,15 +21,16 @@ case $1 in ;; 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 diff --git a/tools/pd-ut/ut.go b/tools/pd-ut/ut.go index dbbd88b868a..9419363c152 100644 --- a/tools/pd-ut/ut.go +++ b/tools/pd-ut/ut.go @@ -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 @@ -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() } @@ -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) } @@ -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 @@ -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)) @@ -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...)