Repository navigation
docs(trace): pass the JVM agent to Maven tests through Surefire's argLine #3057
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d444a09
docs(trace): pass the JVM agent to Maven tests through Surefire's arg…
vitali87 96e7734
test(context): list the server's derived project in the MCP scope test
vitali87 d325108
Merge remote-tracking branch 'origin/main' into mm/claude/jvm-trace-m…
vitali87 5c96265
Merge main into claude/jvm-trace-maven-argline-2876
claude 156d9da
docs(trace): keep flags already in the pom's Surefire argLine
vitali87 a2babc4
docs(trace): the test JVM the agent attaches to must be JDK 24 or newer
vitali87 33014e4
Merge remote-tracking branch 'origin/main' into claude/jvm-trace-mave…
vitali87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| """The JVM tracing guide's Maven recipe reaches the forked test JVM. | ||
|
|
||
| Surefire runs the tests in a forked JVM (`forkCount=1` by default), which | ||
| takes its flags from `argLine`. `MAVEN_OPTS` only sets the JVM running Maven | ||
| itself, so the guide's `MAVEN_OPTS='-javaagent:...' mvn test` attached the | ||
| agent to Maven and traced no test method (issue #2876). | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| _GUIDE = Path(__file__).resolve().parents[2] / "docs" / "guide" / "dynamic-tracing.md" | ||
|
|
||
|
|
||
| def _jvm_recipe() -> str: | ||
| """The attach recipe and the prose under it, up to the section's demo.""" | ||
| text = _GUIDE.read_text(encoding="utf-8") | ||
| start = text.index("Attach it to any JVM workload") | ||
| return text[start : text.index("\n![", start)] | ||
|
|
||
|
|
||
| def test_maven_passes_the_agent_through_surefire_arg_line() -> None: | ||
| recipe = _jvm_recipe() | ||
| assert "mvn test -DargLine='-javaagent:" in recipe, recipe | ||
| # The options carry a `;`, which the quotes keep from ending the command. | ||
| assert "include=com.example;repo=" in recipe.split("-DargLine='", 1)[1] | ||
|
|
||
|
|
||
| def test_maven_opts_is_not_offered_for_a_forked_test_run() -> None: | ||
| recipe = _jvm_recipe() | ||
| assert "MAVEN_OPTS='-javaagent" not in recipe, recipe | ||
| assert "forkCount=0" in recipe, recipe | ||
|
|
||
|
|
||
| def test_a_pom_that_already_sets_arg_line_is_covered() -> None: | ||
| # JaCoCo and others set argLine; replacing it would drop their agent. | ||
| assert "@{argLine}" in _jvm_recipe() | ||
|
|
||
|
|
||
| def test_flags_already_in_the_surefire_arg_line_are_kept() -> None: | ||
| # `@{argLine}` reads the property a plugin sets, not the flags the element | ||
| # held, and without that property the test JVM cannot start. A pom's | ||
| # `<argLine>` also wins over `-DargLine`, so those flags need the agent. | ||
| recipe = _jvm_recipe() | ||
| assert "<argLine>-Xmx512m -javaagent:...</argLine>" in recipe, recipe | ||
| assert "overrides `-DargLine`" in recipe, recipe | ||
|
|
||
|
|
||
| def test_the_test_jvm_must_be_new_enough_for_the_agent() -> None: | ||
| # The agent is built with `--release 24`; an older forked test JVM, which | ||
| # a toolchain can pick even when Maven itself runs on JDK 24, aborts with | ||
| # UnsupportedClassVersionError before any test runs. | ||
| recipe = _jvm_recipe() | ||
| assert "JDK 24 or newer" in recipe, recipe | ||
| assert "toolchain" in recipe, recipe | ||
|
|
||
|
|
||
| def test_the_gradle_line_is_unchanged() -> None: | ||
| assert "test { jvmArgs" in _jvm_recipe() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.