From 1944513aa411032020bb73882165a432cb3fc71c Mon Sep 17 00:00:00 2001 From: Cal Jacobson Date: Fri, 8 Jul 2022 20:27:30 +0000 Subject: [PATCH 1/4] fix debug detection --- .../src/docs/asciidoc/user-guide/writing-tests.adoc | 3 ++- .../junit/platform/commons/util/RuntimeUtils.java | 13 +++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/documentation/src/docs/asciidoc/user-guide/writing-tests.adoc b/documentation/src/docs/asciidoc/user-guide/writing-tests.adoc index 568c72b689a..5b25cf8e26c 100644 --- a/documentation/src/docs/asciidoc/user-guide/writing-tests.adoc +++ b/documentation/src/docs/asciidoc/user-guide/writing-tests.adoc @@ -2177,7 +2177,8 @@ JUnit Jupiter supports the `junit.jupiter.execution.timeout.mode` configuration to configure when timeouts are applied. There are three modes: `enabled`, `disabled`, and `disabled_on_debug`. The default mode is `enabled`. A VM runtime is considered to run in debug mode when one of its input parameters starts -with `-agentlib:jdwp`. This heuristic is queried by the `disabled_on_debug` mode. +with `-agentlib:jdwp` or one of its input parameters is `-Xdebug`. +This heuristic is queried by the `disabled_on_debug` mode. [[writing-tests-parallel-execution]] diff --git a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/RuntimeUtils.java b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/RuntimeUtils.java index 13f0ccfeeb1..3b7a2818cee 100644 --- a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/RuntimeUtils.java +++ b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/RuntimeUtils.java @@ -40,16 +40,9 @@ private RuntimeUtils() { * Try to determine whether the VM was started in debug mode or not. */ public static boolean isDebugMode() { - Optional> optionalArguments = getInputArguments(); - if (!optionalArguments.isPresent()) { - return false; - } - for (String argument : optionalArguments.get()) { - if (argument.startsWith("-agentlib:jdwp")) { - return true; - } - } - return false; + return getInputArguments().map( + args -> args.stream().anyMatch(arg -> "-Xdebug".equals(arg) || arg.startsWith("-agentlib:jdwp"))).orElse( + false); } /** From d731f62c05b02cd1cc2cba0ed06d9c286328e776 Mon Sep 17 00:00:00 2001 From: Cal Jacobson Date: Sun, 10 Jul 2022 21:16:54 +0000 Subject: [PATCH 2/4] apply feedback from @sbrannen --- documentation/src/docs/asciidoc/user-guide/writing-tests.adoc | 4 ++-- .../java/org/junit/platform/commons/util/RuntimeUtils.java | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/documentation/src/docs/asciidoc/user-guide/writing-tests.adoc b/documentation/src/docs/asciidoc/user-guide/writing-tests.adoc index 5b25cf8e26c..8691f648b82 100644 --- a/documentation/src/docs/asciidoc/user-guide/writing-tests.adoc +++ b/documentation/src/docs/asciidoc/user-guide/writing-tests.adoc @@ -2176,8 +2176,8 @@ the result of the test, e.g. mark the test as failed although all assertions wer JUnit Jupiter supports the `junit.jupiter.execution.timeout.mode` configuration parameter to configure when timeouts are applied. There are three modes: `enabled`, `disabled`, and `disabled_on_debug`. The default mode is `enabled`. -A VM runtime is considered to run in debug mode when one of its input parameters starts -with `-agentlib:jdwp` or one of its input parameters is `-Xdebug`. +A VM runtime is considered to run in debug mode when one or more of its input parameters +contains `jdwp`. This heuristic is queried by the `disabled_on_debug` mode. diff --git a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/RuntimeUtils.java b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/RuntimeUtils.java index 3b7a2818cee..0b3a142dcd3 100644 --- a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/RuntimeUtils.java +++ b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/RuntimeUtils.java @@ -40,9 +40,7 @@ private RuntimeUtils() { * Try to determine whether the VM was started in debug mode or not. */ public static boolean isDebugMode() { - return getInputArguments().map( - args -> args.stream().anyMatch(arg -> "-Xdebug".equals(arg) || arg.startsWith("-agentlib:jdwp"))).orElse( - false); + return getInputArguments().map(args -> args.stream().anyMatch(arg -> arg.contains("jdwp"))).orElse(false); } /** From e79c59bed3f76c2fc38c60bc47eb90cd3a97e24c Mon Sep 17 00:00:00 2001 From: Cal Jacobson Date: Fri, 22 Jul 2022 16:27:44 +0000 Subject: [PATCH 3/4] apply feedback from @marcphilipp --- documentation/src/docs/asciidoc/user-guide/writing-tests.adoc | 4 ++-- .../java/org/junit/platform/commons/util/RuntimeUtils.java | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/documentation/src/docs/asciidoc/user-guide/writing-tests.adoc b/documentation/src/docs/asciidoc/user-guide/writing-tests.adoc index 8691f648b82..92432cc8a93 100644 --- a/documentation/src/docs/asciidoc/user-guide/writing-tests.adoc +++ b/documentation/src/docs/asciidoc/user-guide/writing-tests.adoc @@ -2176,8 +2176,8 @@ the result of the test, e.g. mark the test as failed although all assertions wer JUnit Jupiter supports the `junit.jupiter.execution.timeout.mode` configuration parameter to configure when timeouts are applied. There are three modes: `enabled`, `disabled`, and `disabled_on_debug`. The default mode is `enabled`. -A VM runtime is considered to run in debug mode when one or more of its input parameters -contains `jdwp`. +A VM runtime is considered to run in debug mode when one of its input parameters starts +with `-agentlib:jdwp` or `-Xrunjdwp`. This heuristic is queried by the `disabled_on_debug` mode. diff --git a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/RuntimeUtils.java b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/RuntimeUtils.java index 0b3a142dcd3..c946db4bdd7 100644 --- a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/RuntimeUtils.java +++ b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/RuntimeUtils.java @@ -40,7 +40,8 @@ private RuntimeUtils() { * Try to determine whether the VM was started in debug mode or not. */ public static boolean isDebugMode() { - return getInputArguments().map(args -> args.stream().anyMatch(arg -> arg.contains("jdwp"))).orElse(false); + return getInputArguments().map(args -> args.stream().anyMatch( + arg -> arg.startsWith("-agentlib:jdwp") || arg.startsWith("-Xrunjdwp"))).orElse(false); } /** From d50f0df2c71baab696e5790959e4e7920cd17b2f Mon Sep 17 00:00:00 2001 From: Marc Philipp Date: Tue, 26 Jul 2022 16:09:34 +0200 Subject: [PATCH 4/4] Improve formatting --- .../java/org/junit/platform/commons/util/RuntimeUtils.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/RuntimeUtils.java b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/RuntimeUtils.java index c946db4bdd7..020f23226b0 100644 --- a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/RuntimeUtils.java +++ b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/RuntimeUtils.java @@ -40,8 +40,10 @@ private RuntimeUtils() { * Try to determine whether the VM was started in debug mode or not. */ public static boolean isDebugMode() { - return getInputArguments().map(args -> args.stream().anyMatch( - arg -> arg.startsWith("-agentlib:jdwp") || arg.startsWith("-Xrunjdwp"))).orElse(false); + return getInputArguments() // + .map(args -> args.stream().anyMatch( + arg -> arg.startsWith("-agentlib:jdwp") || arg.startsWith("-Xrunjdwp"))) // + .orElse(false); } /**