JVM instance per test for Tycho - surefire

562 views Asked by At

So long story short, we have some legacy code that causes problems due to static initialization of constants. Some of our tests depend on that and we would like to isolate them into separate JVM instances.

I know that this is fairly easy to do in pure maven - surefire

    <forkCount>1</forkCount>
    <reuseForks>false</reuseForks>

In theory the above code should fork off a new thread for each test class. As I take it, this should get rid of our problems as presumably this is a new instance of the JVM that this test is getting run into, hence all the static initialization/class loading is done again.

So far so good. Unfortunately, we are using tycho-surefire (0.16) which does not seem to have that option. My question is whether there is any trick that can allow us to overcome this problem.

For example, how is the parallel option for the Junit runner provider working for tycho?

<parallel>classes</parallel>
<useUnlimitedThreads>true</useUnlimitedThreads>

Would the above piece of code achieve similar result? Is there guarantee that each test class shall run in its own JVM ? I assume that if we specify for unlimited threads, the number of threads will equal the number of test class if our parallelism granularity is "classes".

I hope there is someone who can help me a bit with this mess.

+++++++++++++++++++++++++++ Some New Findings +++++++++++++++++++++++++++++++++

Interestingly enough, the following options fix the problem.

            <threadCount>10</threadCount>
            <perCoreThreadCount>true</perCoreThreadCount>
            <parallel>classes</parallel>

I really cannot explain it to myself why is this the case. These options do not fork a separate JVM for each test class.It actually runs it in a separate thread within the same JVM. Cannot fork a JVM as this does not seem to be supported by Tycho - surefire. Our main problems stem from the eclipse osgi container construction which is constructed with the statically initialized values that are causing problems. Could it be the case that when you are paralleling tests this way in Tycho, it actually forks the JVM or does something strange that reconstructs the OSGI container and reloads certain classes. Could that be the reason for the problem disappearing. All of this seems quite strange. I guess I should take a peek at the tycho-surefire source code.

2

There are 2 answers

0
oberlies On

There is currently no version of Tycho which supports forking more than one VM. The feature request is tracked as bug 380171.

4
abhati On

I dont think surefire will execute each TestSuite classes in a separate JVM .

<parallel>classes</parallel>

If the above property is set JVM will be launched once and runner will spawn as many threads as the number of testsuite classes and all the test case methods in it will be sequential.

If you are using utility methods in such case which are static ,highly likely they are root cause of your troubles :)