Repository navigation
[ML] Report hung test batches to Test Analytics and fail them fast - #3283
Conversation
A test batch that hangs is killed by CTest after 45 minutes. Boost.Test only
writes its JUnit file on completion, so the killed batch left an empty file,
its cases vanished from the merged results ("0 failures") and Test Analytics
showed nothing, even though the build failed.
- Record batches with no complete JUnit file as failed cases before merging.
- Default TEST_TIMEOUT to 900s for non-debug test steps (was 2700s).
- Run batches under a watchdog that dumps thread stacks just before the
timeout, so the underlying hang can be diagnosed from the log.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
SIP strips DYLD_* variables when /bin/bash starts, so the test binaries
launched by the watchdog wrapper could not find their libraries
("Library not loaded: @rpath/libMlTest.dylib"). Pass the value through a
plain variable and restore it in the wrapper just before the command runs.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Helps tell a stalled host from a hung test, and shows a FIFO that was never connected. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
JUnit recovery can create false failures or hide interrupted tests, while unbounded watchdog diagnostics and incomplete descendant cleanup can prevent reliable timeout handling.
4 open issues
What changed in this PR
This PR makes hung test batches easier to diagnose and report in Test Analytics, without fixing the underlying process-spawner hang.
Changes:
- Synthesizes JUnit failures for missing batch results before merging reports.
- Adds a Unix watchdog to collect diagnostics, terminate stalled batches, and record timeout status.
- Reduces the non-debug Unix CI timeout to 900 seconds while retaining 2700 seconds for debug builds.
| File | Description |
|---|---|
cmake/test-runner.cmake |
Invokes the watchdog and records timeout failure markers. |
cmake/run-with-watchdog.sh |
Adds diagnostic collection and timeout-triggered process termination. |
cmake/run-all-tests-parallel.cmake |
Configures watchdog timing and recovers missing JUnit results. |
.buildkite/scripts/steps/run_tests.sh |
Sets the shorter default timeout for non-debug builds. |
Review effort: Balanced
| # Boost.Test only closes the testsuite element when the run completes | ||
| if(_content MATCHES "</testsuite>") | ||
| continue() | ||
| endif() |
There was a problem hiding this comment.
Fixed in 152af71: batches are now only checked when BOOST_TEST_OUTPUT_FORMAT_FLAGS configures a JUnit logger, and the HRF-only seccomp runner is always skipped.
| if(_content MATCHES "name=\"${_casename}\"") | ||
| continue() | ||
| endif() |
There was a problem hiding this comment.
Fixed in 152af71: only complete elements count as results, matched on both classname and name, so an interrupted case or a same-named case in another suite no longer hides a missing result. The classname match also accepts a dotted or slashed suite path, as I couldn't confirm which form Boost writes.
| dump_diagnostics | ||
| pkill -9 -P "${pid}" 2>/dev/null | ||
| kill -9 "${pid}" 2>/dev/null |
There was a problem hiding this comment.
Fixed in 152af71: diagnostics now run in the background with a fixed budget (15s, ML_WATCHDOG_DIAG_SECONDS). If they have not finished they are abandoned, and the batch is killed regardless. The timeout is also reported through a flag file so the exit status does not depend on a signal race.
| pkill -9 -P "${pid}" 2>/dev/null | ||
| kill -9 "${pid}" 2>/dev/null |
There was a problem hiding this comment.
Fixed in 152af71: the watchdog now freezes the batch's process tree, collects every descendant (including processes in their own process group or session) and then SIGKILLs the whole set, rather than only immediate children. A child whose parent exited before the timeout is reparented and cannot be found this way.
* Recover missing JUnit results only for batches that are expected to write them: JUnit logging configured, and not the HRF-only seccomp runner. * Treat only complete <testcase> elements as results, matched on suite and case name, so an interrupted case is still reported as failed. * Give the watchdog's diagnostics a fixed time budget and kill the batch regardless of whether they finish. * Kill the whole process tree of a timed-out batch, including processes in their own process group, and report the timeout through a flag file so the exit status does not depend on a signal race. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
* Recover missing JUnit results only for batches that are expected to write them: JUnit logging configured, and not the HRF-only seccomp runner. * Treat only complete <testcase> elements as results, matched on suite and case name, so an interrupted case is still reported as failed. * Give the watchdog's diagnostics a fixed time budget and kill the batch regardless of whether they finish. * Kill the whole process tree of a timed-out batch, including processes in their own process group, and report the timeout through a flag file so the exit status does not depend on a signal race. Backport of the follow-up to elastic#3283. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
* Recover missing JUnit results only for batches that are expected to write them: JUnit logging configured, and not the HRF-only seccomp runner. * Treat only complete <testcase> elements as results, matched on suite and case name, so an interrupted case is still reported as failed. * Give the watchdog's diagnostics a fixed time budget and kill the batch regardless of whether they finish. * Kill the whole process tree of a timed-out batch, including processes in their own process group, and report the timeout through a flag file so the exit status does not depend on a signal race. Backport of the follow-up to elastic#3283. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Pinging @elastic/ml-core (Team:ML) |
💚 All backports created successfully
Questions ?Please refer to the Backport tool documentation and see the Github Action logs for details |
…3283) (#3324) A test batch that hangs is killed by CTest after 45 minutes. Boost.Test only writes its JUnit file on completion, so the killed batch left an empty file, its cases vanished from the merged results ("0 failures") and Test Analytics showed nothing, even though the build failed. - Record batches with no complete JUnit file as failed cases before merging. - Default TEST_TIMEOUT to 900s for non-debug test steps (was 2700s). - Run batches under a watchdog that dumps thread stacks just before the timeout, so the underlying hang can be diagnosed from the log. (cherry picked from commit c57bfaa) Co-authored-by: Ed Savage <ed.savage@elastic.co>
…3283) (#3325) A test batch that hangs is killed by CTest after 45 minutes. Boost.Test only writes its JUnit file on completion, so the killed batch left an empty file, its cases vanished from the merged results ("0 failures") and Test Analytics showed nothing, even though the build failed. - Record batches with no complete JUnit file as failed cases before merging. - Default TEST_TIMEOUT to 900s for non-debug test steps (was 2700s). - Run batches under a watchdog that dumps thread stacks just before the timeout, so the underlying hang can be diagnosed from the log. (cherry picked from commit c57bfaa) Co-authored-by: Ed Savage <ed.savage@elastic.co>

Summary
Snapshot builds on
mainand9.6(macOS aarch64 and linux-x86_64) have been failing with a test batch hitting the 2700s CTest timeout. Examples: 7361, 7316, 7310.In 7361 the
CProcessSpawnerRouterTestbatch ran both test bodies, then hung in~CDetachedProcessSpawner->CThread::stop(last log line: "Shutting down spawned process tracker thread"). 7310 hit the same batch and 7316 aCDetachedProcessSpawnerTestbatch. The cause of themain/9.6hang is a lost wakeup in the spawned process tracker thread, which #3287 fixes. This PR does not fix any hang; it makes the next occurrence visible and cheap. One hang on9.5(build 7294,CLoggerTest_testWarnAndErrorThrottling) is unexplained and is tracked in #3320.Test Analytics also showed nothing for the failure: the killed batch left a 0-byte JUnit file, so its cases were missing from the merged file (7361 merged "37 tests, 0 failures" against 39 normally).
Changes
run-all-tests-parallel.cmake: a batch with no complete JUnit file (no closing</testsuite>) gets a<failure>entry per missing case before the merge.run_tests.sh:TEST_TIMEOUTdefaults to 900s for non-debug builds (slowest passing batch seen ~150s). Debug builds keep 2700s.cmake/run-with-watchdog.sh, used bytest-runner.cmakeon Unix: 30s before the timeout it dumps stacks (sampleon macOS;/procthread state plusgdb/eu-stackif present on Linux), kills the batch and exits 124.Testing
Locally on macOS, against a fake
ml_test_controllerwhosetestTerminateAndHasChild...batch hangs: the watchdog fired and logged diagnostics, the batch failed in 13s, and the merged JUnit reported 39 tests with 2 failures. A normal run with the real binary passed 20/20 with no synthesized entries.