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/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/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 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;