Skip to content

Commit 18a31de

Browse files
authored
Ignore Intellij idea rmi/jmx threads (attached debugger/ ctrl-c watcher/ thread dumper) (#26)
* Ignore intellij debugger threads. * Detect and ignore intellij rmi threads.
1 parent 4c94cf6 commit 18a31de

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

randomizedtesting-jupiter/src/main/java/com/carrotsearch/randomizedtesting/jupiter/DetectThreadLeaks.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ enum Scope {
5757
* <p>Annotations are collected hierarchically from the class and its superclasses, and the
5858
* filters from all levels are combined.
5959
*
60+
* <p>The default value of this annotation is {@link SystemThreadFilter} which excludes many known
61+
* system and other ignorable threads. Add this filter explicitly when you redeclare the
62+
* exclusions or omit it if you'd like to detect those system threads.
63+
*
6064
* @see SystemThreadFilter
6165
*/
6266
@Target({ElementType.TYPE})

randomizedtesting-jupiter/src/main/java/com/carrotsearch/randomizedtesting/jupiter/SystemThreadFilter.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,18 @@ public boolean test(Thread t) {
2222
return true;
2323
}
2424

25-
// These are some of the "known" threads that should be ignored.
2625
var tName = t.getName();
26+
27+
// Intellij Idea attaches to forked test processes using jmx/rmi. This is asynchronous and
28+
// unpredictable.
29+
if (Boolean.getBoolean("intellij.debug.agent")) {
30+
// JMX server connection timeout
31+
if (tName.startsWith("JMX server connection timeout") || tName.startsWith("RMI TCP")) {
32+
return true;
33+
}
34+
}
35+
36+
// These are some of the "known" threads that should be ignored.
2737
return switch (tName) {
2838
case "JFR request timer",
2939
"YJPAgent-Telemetry",

randomizedtesting-jupiter/src/test/java/com/carrotsearch/randomizedtesting/tests/F005_ThreadLeaks.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import static org.junit.platform.testkit.engine.TestExecutionResultConditions.*;
66

77
import com.carrotsearch.randomizedtesting.jupiter.DetectThreadLeaks;
8+
import com.carrotsearch.randomizedtesting.jupiter.Randomized;
9+
import com.carrotsearch.randomizedtesting.jupiter.SystemThreadFilter;
810
import com.carrotsearch.randomizedtesting.tests.infra.IgnoreInStandaloneRuns;
911
import java.time.Duration;
1012
import java.util.ArrayList;
@@ -387,6 +389,25 @@ void testMethod() {
387389
}
388390
}
389391

392+
@Test
393+
void intellijJmxThreads() {
394+
collectExecutionResults(testKitBuilder(IntellijThreads.class))
395+
.results()
396+
.allEvents()
397+
.assertThatEvents()
398+
.doNotHave(event(finishedWithFailure()));
399+
}
400+
401+
@DetectThreadLeaks(scope = DetectThreadLeaks.Scope.SUITE)
402+
@DetectThreadLeaks.ExcludeThreads(value = {SystemThreadFilter.class})
403+
@Randomized
404+
static class IntellijThreads { // extends IgnoreInStandaloneRuns {
405+
@Test
406+
void testMethod() throws Exception {
407+
Thread.sleep(1000);
408+
}
409+
}
410+
390411
@DetectThreadLeaks(scope = DetectThreadLeaks.Scope.SUITE)
391412
@DetectThreadLeaks.ExcludeThreads(ExcludeNamedAFilter.class)
392413
static class ExcludedByClassFilter extends IgnoreInStandaloneRuns {

0 commit comments

Comments
 (0)