I have a project with (so far) 17 test classes containing over 100 test methods. When I try to run all my tests in one go, I end up getting a PermGen OutOfMemoryError. This happens because the test EAR has to be redeployed for each class, and AS7's classloading system recreates all my classes over and over. My understanding is that classes should get garbage collected when they're no longer needed, so I analyzed some heap dumps to find out why that wasn't happening.
Turns out that something is putting a TestNG result in a ThreadLocal on a thread in the container and never clearing it. This is a problem because the test result class is part of the deployment, and it holds a reference to the classloader that loaded the deployment, which holds references to all the other classes in the deployment. Since Arquillian doesn't restart JBoss between test classes (and, by extension, deployments), all the classes from all the deployments accumulate until the PermGen space is exhausted. I can try upping the PermGen space as a workaround, but every test class I add will make the problem progressively worse, so it would be much better to fix the leak.
So, is this ThreadLocal usage something Arquillian is doing? Or is it something TestNG is doing?
Arquillian does use some ThreadLocals, but it should clean up after it self..
Looking at the TestNG code:
This code holds a ThreadLocal with the TestResult:
and set again here in the final block https://github.com/cbeust/testng/blob/master/src/main/java/org/testng/internal/Invoker.java#L584
Looking at the other uses of this method, it should probably be set to null in the final block. so this looks to me like a bug in TestNG.
I'll ping Cedric to confirm..
No, Maven Central doesn't allow SNAPSHOTS and it's usually a hassle to explain to people how to hook up their build to check the SNAPSHOT repositories :-)
You can, however, use the beta jar in your maven build with systemPath: