Navigation Menu

Skip to content
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

Improve debug mode detection in JUnit Jupiter #2973

Merged
merged 4 commits into from Jul 26, 2022
Merged

Improve debug mode detection in JUnit Jupiter #2973

merged 4 commits into from Jul 26, 2022

Conversation

cj81499
Copy link
Contributor

@cj81499 cj81499 commented Jul 8, 2022

Overview

I'm handling an upgrade from JUnit 4 to JUnit 5 and noticed that disabling our timeouts with -Djunit.jupiter.execution.timeout.mode=disabled_on_debug is not working as expected.

We use VSCode as our editor/IDE. When using the Debugger for Java extension to debug tests.

When ran in my project, the following "test" prints [-ea, -Djunit.jupiter.execution.timeout.mode=disabled_on_debug, -XX:+ShowCodeDetailsInExceptionMessages, -Dfile.encoding=UTF-8]

When ran with the debugger in my project, the following "test" prints [-Xdebug, -Xnoagent, -Djava.compiler=NONE, -Xrunjdwp:transport=dt_socket,address=localhost:34399,server=n,suspend=y, -ea, -Djunit.jupiter.execution.timeout.mode=disabled_on_debug, -XX:+ShowCodeDetailsInExceptionMessages, -Dfile.encoding=UTF-8]

@Test
void test() {
  System.out.println(ManagementFactory.getRuntimeMXBean().getInputArguments());
}

Notably, the first 4 argument of the output from the run using the debugger are not present from the run without the debugger.

JUnit 4 detected -Xdebug as a sign of debugging, but (prior to this change) JUnit 5 does not, leading to the unexpected timeouts while debugging (and regression, compared to JUnit 4). Since JUnit 4 used it, I figured -Xdebug was the best thing to detect.

I'm not really sure how to test this kind of thing, but I'm open to suggestions.


I hereby agree to the terms of the JUnit Contributor License Agreement.


Definition of Done

@cj81499 cj81499 marked this pull request as ready for review July 8, 2022 21:03
@sbrannen
Copy link
Member

sbrannen commented Jul 9, 2022

Since JUnit 4 used it, I figured -Xdebug was the best thing to detect.

I don't recall the details, but I believe that was not picked for a reason.

It might be better to just check if one of the arguments contains jdwp (see Java Debug Wire Protocol.

That would then work for -Xrunjdwp as well as -agentlib:jdwp.

@sbrannen sbrannen changed the title fix debug detection Improve debug mode detection in JUnit Jupiter Jul 9, 2022
@sbrannen
Copy link
Member

sbrannen commented Jul 9, 2022

related discussion in #2026 (comment)

@cj81499
Copy link
Contributor Author

cj81499 commented Jul 9, 2022

Thanks for the feedback. I expect I'll have time to fix this up on Monday.

Any input on writing tests? Or are you comfortable without?

@sbrannen
Copy link
Member

Any input on writing tests? Or are you comfortable without?

It appears we don't have any tests for that (at least not with the initial commit ddb8c61), so I guess it will be OK without additional tests for this particular feature.

@marcphilipp marcphilipp added this to the 5.9 GA milestone Jul 22, 2022
@marcphilipp marcphilipp merged commit 2aaf24c into junit-team:main Jul 26, 2022
@marcphilipp
Copy link
Member

@cj81499 Thanks for your contribution! 👍

@cj81499
Copy link
Contributor Author

cj81499 commented Jul 26, 2022

@marcphilipp thanks for your help getting it merged!
Selfishly, I'm happy to have it fixed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants