Well, here's the innards of my test class itself so you might be able to
see if I'm doing something idiotic (the
H2ConnectionDescriptor.getProcessId() method is one of my own devising that
uses the JMX subsystem to come up with the process ID; you can disregard
here):
@Test
public void test1() throws Exception {
System.out.println("Thread for TestCaseH2ConnectionDescriptor.test1():
surefire.forkNumber is: " + System.getProperty("surefire.forkNumber") + ";
pid is: " + H2ConnectionDescriptor.getProcessId() + "; thread is: " +
Thread.currentThread().getId());
Thread.currentThread().sleep(1000L);
}
@Test
public void test2() throws Exception {
System.out.println("Thread for TestCaseH2ConnectionDescriptor.test2():
surefire.forkNumber is: " + System.getProperty("surefire.forkNumber") + ";
pid is: " + H2ConnectionDescriptor.getProcessId() + "; thread is: " +
Thread.currentThread().getId());
Thread.currentThread().sleep(1000L);
}
@Test
public void test3() throws Exception {
System.out.println("Thread for TestCaseH2ConnectionDescriptor.test3():
surefire.forkNumber is: " + System.getProperty("surefire.forkNumber") + ";
pid is: " + H2ConnectionDescriptor.getProcessId() + "; thread is: " +
Thread.currentThread().getId());
Thread.currentThread().sleep(1000L);
}
@Test
public void test4() throws Exception {
System.out.println("Thread for TestCaseH2ConnectionDescriptor.test4():
surefire.forkNumber is: " + System.getProperty("surefire.forkNumber") + ";
pid is: " + H2ConnectionDescriptor.getProcessId() + "; thread is: " +
Thread.currentThread().getId());
Thread.currentThread().sleep(1000L);
}
@Test
public void test5() throws Exception {
System.out.println("Thread for TestCaseH2ConnectionDescriptor.test5():
surefire.forkNumber is: " + System.getProperty("surefire.forkNumber") + ";
pid is: " + H2ConnectionDescriptor.getProcessId() + "; thread is: " +
Thread.currentThread().getId());
Thread.currentThread().sleep(1000L);
}
When I run this with the following configuration:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<forkCount>2</forkCount>
<reuseForks>false</reuseForks>
<systemPropertyVariables>
<surefire.forkNumber>${surefire.forkNumber}</surefire.forkNumber>
</systemPropertyVariables>
</configuration>
</plugin>
...the output resembles this:
Thread for TestCaseH2ConnectionDescriptor.test1(): surefire.forkNumber is:
null; pid is: 2108; thread is: 1
Thread for TestCaseH2ConnectionDescriptor.test2(): surefire.forkNumber is:
null; pid is: 2108; thread is: 1
Thread for TestCaseH2ConnectionDescriptor.test3(): surefire.forkNumber is:
null; pid is: 2108; thread is: 1
Thread for TestCaseH2ConnectionDescriptor.test4(): surefire.forkNumber is:
null; pid is: 2108; thread is: 1
Thread for TestCaseH2ConnectionDescriptor.test5(): surefire.forkNumber is:
null; pid is: 2108; thread is: 1
I've also tried this by explicitly pulling in the JUnit 4.7 provider, but
that made no difference (I thought perhaps SureFire was picking up the
wrong provider, since the documentation about the algorithm indicates that
the 47 provider won't be used without the <parallel> property, which I have
no use for here (yet :-)).
Best,
Laird
On Wed, Sep 25, 2013 at 2:07 PM, Andreas Gudian <[email protected]>wrote:
> That sounds bad. reuseForks=false and forkCount=2 should spawn up to two
> JVMs in parallel (a new one for each test class), and the foobar parameter
> should be populated with a value of 1 or 2 and be distinct between
> concurrently running JVMs. If that doesn't work, you found a bug. :)
>
> What happens when you use reuseForks=true? Does it work for you in that
> case?
>
>
>
> 2013/9/25 Laird Nelson <[email protected]>
>
> > Having trouble believing what I'm seeing, especially given the excellent
> > documentation at
> >
> >
> http://maven.apache.org/surefire/maven-surefire-plugin/examples/fork-options-and-parallel-execution.html
> > ,
> > but it seems to me that specifying <forkCount>2</forkCount> and
> > <reuseForks>false</reuseForks> using SureFire 2.16 simply doesn't do
> > anything (it seems to behave as though I had specified nothing).
> >
> > The debug output shows that the default value for forkMode (which I
> haven't
> > specified, per the documentation) is (as you would expect) 1, and the
> > behavior from my tests seems to indicate that this is trumping (i.e.
> > there's only one VM forked).
> >
> > Furthermore, including something like this:
> >
> > <systemPropertyVariables>
> > <foobar>${surefire.forkNumber}</foobar>
> > </systemPropertyVariables>
> >
> > ...yields null in my tests for:
> >
> > System.getProperty("foobar");
> >
> > ...but if I change it to
> >
> > <systemPropertyVariables>
> > <foobar>bizbaw</foobar>
> > </systemPropertyVariables>
> >
> > ...then System.getProperty("foobar") yields "bizbaw" as I'd expect.
> >
> > The net behavior makes me think that I'm missing something fundamental,
> or
> > that the documentation has instructed me to do something that doesn't
> work.
> >
> > My JUnit dependency is 4.11 if it matters.
> >
> > Best,
> > Laird
> >
> > --
> > http://about.me/lairdnelson
> >
>
--
http://about.me/lairdnelson