Skip to content

Conversation

@rwgk
Copy link
Collaborator

@rwgk rwgk commented Dec 22, 2025

Description

This PR improves the C++ test infrastructure to provide better visibility into test execution and prevent CI hangs from going undiagnosed.

Changes

Test timeouts:

  • Add timeout-minutes: 3 to all cpptest steps in CI workflows (18 total)

Unbuffered output:

  • Add USES_TERMINAL to add_custom_target commands in CMakeLists.txt files to prevent ninja from buffering test output (critical for diagnosing hangs)

Progress reporter (catch.cpp):

  • Add custom ProgressReporter that prints [ RUN ], [ OK ], [ FAILED ] for each test
  • Add [ STARTING ] and [ DONE ] timestamps with UTC time
  • Add SIGTERM signal handler to print [ SIGNAL ] when tests are killed by timeout
  • Add test summary showing total test cases and assertions

Skip macro:

Example output:

[ STARTING ] 2025-12-22 03:40:01.123Z
[  PYTHON  ] 3.14.0a2+ (free-threaded)
[ RUN      ] Single Subinterpreter
[       OK ] Single Subinterpreter
[ RUN      ] Move Subinterpreter
[ SKIPPED  ] Skipped on free-threaded Python 3.14+ (see PR #5940)
[       OK ] Move Subinterpreter
[ RUN      ] GIL Subinterpreter
[       OK ] GIL Subinterpreter
[  PASSED  ] 21 test cases, 1589 assertions.
[ DONE     ] 2025-12-22 03:40:01.919Z (result 0)

Background

We were in the dark for months about which test was hanging on free-threaded Python 3.14 because:

  1. CI workflows had no timeout, so jobs would run until our general 90 minute limit
  2. Ninja buffers subprocess output, so no test progress was visible
  3. When a test hung, there was no indication which test or why

This PR ensures that future hangs will be immediately diagnosable from CI logs.

Related

rwgk added 4 commits December 21, 2025 19:19
This commit improves the C++ test infrastructure to ensure test output
is visible in CI logs, and disables a test that hangs on free-threaded
Python 3.14+.

Changes:

## CI/test infrastructure improvements

- .github/workflows: Added `timeout-minutes: 3` to all C++ test steps
  to prevent indefinite hangs.

- tests/**/CMakeLists.txt: Added `USES_TERMINAL` to C++ test targets
  (cpptest, test_cross_module_rtti, test_pure_cpp) to ensure output is
  shown immediately rather than buffered and possibly lost on crash/timeout.

- tests/test_with_catch/catch.cpp: Added a custom Catch2 progress reporter
  with timestamps, Python version info, and a SIGTERM handler to make test
  execution and failures clearly visible in CI logs.

## Disabled hanging test

- The "Move Subinterpreter" test is disabled on free-threaded Python 3.14+
  due to a hang in Py_EndInterpreter() when the subinterpreter is destroyed
  from a different thread than it was created on. Work on fixing the
  underlying issue will continue under PR pybind#5940.

Context: We were in the dark for months (since we started testing with
Python 3.14t) because CI logs gave no clue about the root cause of hangs.
This led to ignoring intermittent hangs (mostly on macOS). Our hand was
forced only with the Python 3.14.1 release, when hangs became predictable
on all platforms.

For the full development history of these changes, see PR pybind#5933.
Print the total number of test cases and assertions at the end of the
test run, making it easy to spot if tests are disabled or added.

Example output:
  [  PASSED  ] 20 test cases, 1589 assertions.
Catch2 v2 doesn't have native skip support (v3 does with SKIP()).
This macro allows tests to be skipped with a visible message while
still appearing in the test list.

Use this for the Move Subinterpreter test on free-threaded Python 3.14+
so it shows as skipped rather than being conditionally compiled out.

Example output:
  [ RUN      ] Move Subinterpreter
  [ SKIPPED ] Skipped on free-threaded Python 3.14+ (see PR pybind#5940)
  [       OK ] Move Subinterpreter
@rwgk rwgk merged commit 78381e5 into pybind:master Dec 22, 2025
87 checks passed
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Dec 22, 2025
@rwgk rwgk deleted the skip_move_subinterpreter_and_progress_reporter branch December 22, 2025 05:29
@rwgk rwgk removed the needs changelog Possibly needs a changelog entry label Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant