This message was deleted.
# community-support
s
This message was deleted.
r
I really want to detect when
--tests
has not been passed, so I can set an env var when this happens. Then the default can be a long timeout but a short timeout can be used when all the tests are being run.
v
I'm not sure whether you can do that using public API. If you don't mind using internal API, you can probably get
filter
from the
Test
task, cast it to
DefaultTestFilter
and there check
commandLineIncludePatterns
.
r
Thanks - unfortunately that seems to be set after the
test {}
block is evaluated. I can see it after being set in a
beforeSuite
listener, but that's too late to set the environment.
v
Maybe you should just make it explicit, either by some Gradle property, ro by defining two separate tasks.
r
Probably a simpler solution is just to set the short timeout env var for all tests run by gradle, and tell people to use the JUnit runner in IntelliJ if they want to debug.
Thanks for the help.
e
set the timeout to long if
System.getProperty("idea.version")
?
r
I'd rather not tie it to a specific IDE. I suppose the ideal would be to know when you're debugging... I don't know off the top of my head if you can find that out dynamically in a JVM. Will have a look.
e
hmm. inside the JVM, it should be detectable (since JUnit manages to implement
-Djunit.jupiter.execution.timeout.mode=disabled_on_debug
somehow)
https://junit.org/junit5/docs/snapshot/user-guide/index.html#writing-tests-declarative-timeouts-mode
A VM runtime is considered to run in debug mode when one of its input parameters starts with
-agentlib:jdwp
or
-Xrunjdwp
.
e
definitely a heuristic since debuggers can be attached via JVMTI or other means, I wonder why there isn't something simple like https://developer.android.com/reference/android/os/Debug#isDebuggerConnected() 😕
but it's probably good enough for your purposes, that's how the IDE probably attaches
r
I'd hazard a guess they think changing the code because you are debugging may defeat the object - they may have a point!
Great way to create heisenbugs.
Thanks all, plenty of stuff to play with.
e
you're already changing behavior by attaching a debugger - timing, locking, and JIT optimizations - so there's plenty of room for heisenbugs even without an official method for detecting debuggers. but I'm getting a bit far astray from the topic 🙂