From bf9b5435f172bcdf2365d53fa741a7bff04531f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=81=E5=BC=8C?= Date: Thu, 30 Apr 2026 15:41:09 +0800 Subject: [PATCH 1/2] feat(test): isolate test working directories and enable parallel ctest execution - Set unique WORKING_DIRECTORY per test binary via cc_test()/cuda_test() to prevent filesystem path conflicts when running tests in parallel. Each test runs in \${CMAKE_BINARY_DIR}/test_tmp/\${test_name}/. - Enable parallel ctest execution in the unittest target with ProcessorCount-based --parallel flag (defaults to NPROC/2). - Set TEST_BINARY_DIR environment variable for crash recovery tests so they can locate helper binaries from isolated working directories. - Update LocateDataGenerator() and LocateOptimizeGenerator() to search TEST_BINARY_DIR and TEST_BINARY_DIR/bin for helper executables. --- cmake/bazel.cmake | 19 +++++++++++++++---- tests/db/crash_recovery/CMakeLists.txt | 3 +++ .../crash_recovery/optimize_recovery_test.cc | 6 ++++++ .../db/crash_recovery/write_recovery_test.cc | 6 ++++++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/cmake/bazel.cmake b/cmake/bazel.cmake index 262f721b..95d40e99 100644 --- a/cmake/bazel.cmake +++ b/cmake/bazel.cmake @@ -318,10 +318,17 @@ if(NOT TARGET unittest) # iOS: build-only target; tests are run on simulator separately add_custom_target(unittest) else() + include(ProcessorCount) + ProcessorCount(NPROC) + if(NPROC EQUAL 0) + set(NPROC 1) + endif() + math(EXPR PARALLEL_JOBS "(${NPROC} + 1) / 2") add_custom_target( unittest COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure --build-config $ + --parallel ${PARALLEL_JOBS} ) endif() endif() @@ -1110,16 +1117,18 @@ function(cc_test) "${CC_ARGS_UNPARSED_ARGUMENTS}" ) add_dependencies(unittest ${CC_ARGS_NAME}) + set(TEST_WORKING_DIR "${CMAKE_BINARY_DIR}/test_tmp/${CC_ARGS_NAME}") + file(MAKE_DIRECTORY "${TEST_WORKING_DIR}") add_custom_target( unittest.${CC_ARGS_NAME} COMMAND $ "${CC_ARGS_ARGS}" - WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + WORKING_DIRECTORY ${TEST_WORKING_DIR} DEPENDS ${CC_ARGS_NAME} ) add_test( NAME ${CC_ARGS_NAME} COMMAND $ "${CC_ARGS_ARGS}" - WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + WORKING_DIRECTORY ${TEST_WORKING_DIR} ) endfunction() @@ -1925,16 +1934,18 @@ function(cuda_test) "${CUDA_ARGS_UNPARSED_ARGUMENTS}" ) add_dependencies(unittest ${CUDA_ARGS_NAME}) + set(TEST_WORKING_DIR "${CMAKE_BINARY_DIR}/test_tmp/${CUDA_ARGS_NAME}") + file(MAKE_DIRECTORY "${TEST_WORKING_DIR}") add_custom_target( unittest.${CUDA_ARGS_NAME} COMMAND $ "${CUDA_ARGS_ARGS}" - WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + WORKING_DIRECTORY ${TEST_WORKING_DIR} DEPENDS ${CUDA_ARGS_NAME} ) add_test( NAME ${CUDA_ARGS_NAME} COMMAND $ "${CUDA_ARGS_ARGS}" - WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + WORKING_DIRECTORY ${TEST_WORKING_DIR} ) endfunction() diff --git a/tests/db/crash_recovery/CMakeLists.txt b/tests/db/crash_recovery/CMakeLists.txt index f737b40d..7a872435 100644 --- a/tests/db/crash_recovery/CMakeLists.txt +++ b/tests/db/crash_recovery/CMakeLists.txt @@ -77,5 +77,8 @@ foreach(CC_SRCS ${ALL_TEST_SRCS}) ) add_dependencies(${CC_TARGET} data_generator) add_dependencies(${CC_TARGET} collection_optimizer) + set_tests_properties(${CC_TARGET} PROPERTIES + ENVIRONMENT "TEST_BINARY_DIR=${PROJECT_BINARY_DIR}" + ) cc_test_suite(zvec_crash_recovery ${CC_TARGET}) endforeach() diff --git a/tests/db/crash_recovery/optimize_recovery_test.cc b/tests/db/crash_recovery/optimize_recovery_test.cc index 620c5dfc..a947809a 100644 --- a/tests/db/crash_recovery/optimize_recovery_test.cc +++ b/tests/db/crash_recovery/optimize_recovery_test.cc @@ -65,6 +65,12 @@ static std::string LocateOptimizeGenerator() { } #endif + const char *test_binary_dir = std::getenv("TEST_BINARY_DIR"); + if (test_binary_dir != nullptr) { + candidates.push_back(std::string(test_binary_dir) + "/"); + candidates.push_back(std::string(test_binary_dir) + "/bin/"); + } + for (auto &p : candidates) { p += base_name; #ifdef _WIN32 diff --git a/tests/db/crash_recovery/write_recovery_test.cc b/tests/db/crash_recovery/write_recovery_test.cc index 6eed2e0f..fd47e379 100644 --- a/tests/db/crash_recovery/write_recovery_test.cc +++ b/tests/db/crash_recovery/write_recovery_test.cc @@ -62,6 +62,12 @@ static std::string LocateDataGenerator() { } #endif + const char *test_binary_dir = std::getenv("TEST_BINARY_DIR"); + if (test_binary_dir != nullptr) { + candidates.push_back(std::string(test_binary_dir) + "/"); + candidates.push_back(std::string(test_binary_dir) + "/bin/"); + } + for (auto &p : candidates) { p += base_name; From 74aede8120a7aea74015f11f9fc72a34cb3f268f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=81=E5=BC=8C?= Date: Thu, 30 Apr 2026 17:34:04 +0800 Subject: [PATCH 2/2] feat(test): enable parallel Python test execution with pytest-xdist Add pytest-xdist dependency and configure -n=auto to run Python tests in parallel across all available CPU cores. Update CI workflows and cibuildwheel test-requires accordingly. --- .github/workflows/03-macos-linux-build.yml | 1 + .github/workflows/05-windows-build.yml | 1 + .github/workflows/nightly_coverage.yml | 1 + pyproject.toml | 4 +++- 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/03-macos-linux-build.yml b/.github/workflows/03-macos-linux-build.yml index 1dd1e45c..652375e6 100644 --- a/.github/workflows/03-macos-linux-build.yml +++ b/.github/workflows/03-macos-linux-build.yml @@ -87,6 +87,7 @@ jobs: cmake==3.30.0 \ ninja==1.11.1 \ pytest \ + pytest-xdist \ scikit-build-core \ setuptools_scm shell: bash diff --git a/.github/workflows/05-windows-build.yml b/.github/workflows/05-windows-build.yml index 9922e037..0db11c20 100644 --- a/.github/workflows/05-windows-build.yml +++ b/.github/workflows/05-windows-build.yml @@ -64,6 +64,7 @@ jobs: cmake==3.30.0 ` ninja==1.11.1 ` pytest ` + pytest-xdist ` scikit-build-core ` setuptools_scm shell: powershell diff --git a/.github/workflows/nightly_coverage.yml b/.github/workflows/nightly_coverage.yml index 1279496b..458044db 100644 --- a/.github/workflows/nightly_coverage.yml +++ b/.github/workflows/nightly_coverage.yml @@ -59,6 +59,7 @@ jobs: ninja==1.11.1 \ pytest \ pytest-cov \ + pytest-xdist \ scikit-build-core \ setuptools_scm shell: bash diff --git a/pyproject.toml b/pyproject.toml index c7125a33..2b7908fe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,6 +51,7 @@ test = [ "pytest >=8.0", "pytest-cov >=4.1", "pytest-mock >=3.12", + "pytest-xdist >=3.5", "cibuildwheel == 3.4.0", ] docs = [ @@ -142,6 +143,7 @@ addopts = [ "--strict-markers", "--strict-config", "--tb=short", + "-n=auto", ] xfail_strict = true log_cli_level = "INFO" @@ -169,7 +171,7 @@ build = [ "cp314-*", ] build-frontend = "build" -test-requires = ["pytest", "numpy"] +test-requires = ["pytest", "pytest-xdist", "numpy"] test-command = "cd {project} && pytest python/tests -v --tb=short" build-verbosity = 1