Add a 1st migration guide#24
Conversation
Those are my first findings when I migrated my [demo repo](https://github.com/dadoonet/randomizedtesting-demo/) (for talks) to Junit6 / randomizedtesting-jupiter.
dweiss
left a comment
There was a problem hiding this comment.
It's a good concise overview. There are *.md files next to tests that provide similar migration guidance but the top-level file is also fine, thank you.
Yeah. Saw it. It was super helpful BTW. BTW I saw that running from IntelliJ is triggering as well the ThreadLeak detector. I added a class in my repo to avoid this but I'm wondering if we should add it or something similar as another option, may be not within the default system thread filter though. |
|
Which thread is triggering thread leaks? I use intellij and I haven't seen this. |
|
I updated the doc. I'm still not super happy with the "Repeated tests"... Let see if I'm more inspired or feel free to suggest what you think would be more useful. I'm going to share just after this the IntelliJ thing I saw. |
When running for IntelliJ JUnit Runner: When running from the CLI: mvn test -Dtest=RandomizedTest#stopOrIdentifyYourThreads30It passes: The test is: @DetectThreadLeaks
@DetectThreadLeaks.ExcludeThreads({RandomizedTest.FriendlyZombieFilter.class})
@Randomized
class RandomizedTest {
@Test
void stopOrIdentifyYourThreads30() {
LOGGER.info(" ➡️ starting a new Thread");
new Thread(() -> {
while (true) {
try {
Thread.sleep(1000L);
} catch (InterruptedException ignored) {
}
}
}, "friendly-zombie").start();
}
public static class FriendlyZombieFilter implements Predicate<Thread> {
public boolean test(Thread t) {
return "friendly-zombie".equals(t.getName());
}
}
}If I'm adding this: package fr.pilato.talk.randomizedtesting;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.function.Predicate;
/**
* This filter is only needed when running the tests from IntelliJ
*/
public class IntelliJThreadsFilter implements Predicate<Thread> {
private static final Logger LOGGER = LogManager.getLogger();
public boolean test(Thread t) {
boolean intellijThreads = t.getName().startsWith("JMX server") || t.getName().startsWith("RMI TCP Connection");
if (intellijThreads) {
LOGGER.warn("Detected IntelliJ threads [{}], if you are running the tests from IntelliJ, " +
"you can ignore this warning or add [{}] to the thread leak filters",
t.getName(), IntelliJThreadsFilter.class.getSimpleName());
}
return intellijThreads;
}
}And: @DetectThreadLeaks.ExcludeThreads({RandomizedTest.FriendlyZombieFilter.class, IntelliJThreadsFilter.class})Then it passes (of course). |
|
This passes for me without a glitch. How are you launching intellij? the jmx server is odd - I think that check thread leaks annotation is actually doing the right job! :) |
|
If you can share a maven project zip with this, I can try to import it locally as a maven project. I've compared my intellij options but I don't see anything jmx related (I have a newer intellij but this shouldn't matter). |
|
I see it at https://github.com/dadoonet/randomizedtesting-demo/, sorry. Can't reproduce though - it must be something with your intellij; crazy! |
|
I have this: It's not the community edition. Not sure about which one you are using. |
|
There is a difference in how intellij launches subprocesses on MacOS and on Linux. There is a lot going on - the IDE is attaching to the jvm, this triggers jmx/ rmi. I'm not sure why this passes on Linux, still trying to figure this one out. In any case, if you're using the ExcludeThreads annotation, you should also include the built-in filters. Look at the last line in migration notes here - |
|
This looks very much like a race condition - if the initial snapshot of all live threads includes jmx/rmi, the test will pass. Otherwise it'll detect a leak and fail. This affects intellij because it does start rmi services... I'm not sure if it should be excluded or not (as part of the default filter). I'll think about it. Definitely something to consider though. In the meantime, your demo should also include the built-in filters - |

Those are my first findings when I migrated my demo repo (for talks) to Junit6 / randomizedtesting-jupiter.