Skip to content

Issue #838 Implement extension point to run diagnosis tools when forked JVM times out#3372

Open
olamy wants to merge 8 commits into
masterfrom
feature/838-extension-point-timeout
Open

Issue #838 Implement extension point to run diagnosis tools when forked JVM times out#3372
olamy wants to merge 8 commits into
masterfrom
feature/838-extension-point-timeout

Conversation

@olamy

@olamy olamy commented Jun 4, 2026

Copy link
Copy Markdown
Member

Signed-off-by: Olivier Lamy olamy@apache.org

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean install to make sure basic checks pass. A more thorough check will
    be performed on your pull request automatically.
  • You have run the integration tests successfully (mvn -Prun-its clean install).

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

…ed JVM times out

Signed-off-by: Olivier Lamy <olamy@apache.org>
@olamy olamy added the enhancement New feature or request label Jun 4, 2026
@olamy olamy linked an issue Jun 4, 2026 that may be closed by this pull request
@olamy olamy self-assigned this Jun 4, 2026
@olamy olamy added this to the 3.6.0-M2 milestone Jun 4, 2026
@olamy olamy requested a review from Copilot June 4, 2026 21:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Surefire/Failsafe extension point that lets plugins/extensions run diagnostic tooling when a forked test JVM hits forkedProcessTimeoutInSeconds, including a built-in (opt-in) jstack implementation plus ITs and site documentation.

Changes:

  • Introduce ForkedProcessTimeoutExtension SPI + ForkedProcessTimeoutContext API and wire it into the fork timeout/kill path.
  • Add plugin-side dispatcher/context implementation and a built-in JstackTimeoutExtension (disabled by default, configurable via a context map).
  • Add unit tests, an integration test (SUREFIRE-838), and new site docs/menus for the feature.

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
surefire-its/src/test/resources/surefire-838-timeout-extension/src/test/java/surefire838/SleepingTest.java Adds a hanging test used to trigger fork timeout in the IT project.
surefire-its/src/test/resources/surefire-838-timeout-extension/pom.xml Consumer IT POM enabling timeout + configuring extension context keys and adding the extension dependency.
surefire-its/src/test/resources/surefire-838-timeout-extension-ext/src/main/resources/META-INF/services/org.apache.maven.surefire.extensions.ForkedProcessTimeoutExtension Registers the IT extension implementation via ServiceLoader.
surefire-its/src/test/resources/surefire-838-timeout-extension-ext/src/main/java/org/apache/maven/surefire/its/extension/MarkerTimeoutExtension.java Test extension that writes marker files when timeout/exited callbacks fire.
surefire-its/src/test/resources/surefire-838-timeout-extension-ext/pom.xml Builds the IT extension JAR against the new extensions API.
surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire838TimeoutExtensionIT.java Integration test asserting the timeout extension callbacks (and best-effort jstack dump) occur.
surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/util/CommandlineExecutor.java Exposes the underlying Process so the fork PID can be queried.
surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/ForkedProcessTimeoutExtension.java New SPI interface invoked on fork timeout and fork exit.
surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/ForkedProcessTimeoutContext.java New context interface carrying fork diagnostics + extension configuration map.
surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemUtils.java Adds pidOf(Process) (Java 9+ reflective Process.pid()) to support PID reporting.
pom.xml Updates RAT excludes for the new ServiceLoader file in main resources.
maven-surefire-plugin/src/site/site.xml Adds site menu entries for the timeout extension docs.
maven-surefire-plugin/src/site/markdown/timeout-extension-guide.md New detailed guide for enabling built-in jstack and authoring extensions.
maven-surefire-plugin/src/site/markdown/examples/timeout-extension.md New concise example/reference page for the timeout extension SPI.
maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/timeout/TimeoutExtensionDispatcherTest.java Unit tests for dispatcher behavior (fan-out, exception isolation, context propagation, bounded execution).
maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/timeout/JstackTimeoutExtensionTest.java Unit tests for built-in jstack extension enablement and output-location behavior.
maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClientTest.java Adds a test ensuring timeout listener fires once and before KILL is sent.
maven-surefire-common/src/main/resources/META-INF/services/org.apache.maven.surefire.extensions.ForkedProcessTimeoutExtension Registers the built-in JstackTimeoutExtension via ServiceLoader.
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/timeout/TimeoutExtensionDispatcher.java New plugin-side ServiceLoader discovery + bounded callback execution.
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/timeout/JstackTimeoutExtension.java Built-in (opt-in) implementation that captures a jstack dump on timeout.
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/timeout/DefaultForkedProcessTimeoutContext.java Default immutable context implementation for extensions.
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java Adds a one-shot “timeout detected” listener invoked immediately before sending KILL.
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java Wires extension dispatch into fork lifecycle (on-timeout-before-kill + after-exit) and passes context/config.
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java Adds forkedProcessTimeoutExtensionContext parameter and passes it into ForkStarter.


@Test
public void sleepsLongerThanTimeout() throws Exception {
Thread.sleep(120_000L);
olamy and others added 7 commits June 5, 2026 11:04
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Olivier Lamy <olamy@apache.org>
Signed-off-by: Olivier Lamy <olamy@apache.org>
Signed-off-by: Olivier Lamy <olamy@apache.org>
Signed-off-by: Olivier Lamy <olamy@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implements an extension point when test runs into timeout

2 participants