0

I'm using the maven-surefire plugin to execute the Cucumber Runner in parallel. In each of the Runners, I'm invoking a synchronized static method of a Utilities class. But all the Runners running in parallel are able to invoke the method in a non-synchronized way.

@RunWith(CucumberWithSerenity.class)
@CucumberOptions(...)

public class SampleRunner {

    @BeforeClass
    public static void loadLocators() {
            Utilities.doSomething();
        }
}
public class Utilities {

    public synchronized static void doSomething() {
       System.out.println("Start");
       .
       .
       .
       System.out.println("Stop");
    }
}

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M3</version>
    <configuration>
    <includes>
        <include>**/*Runner.java</include>               
    </includes> 
    <parallel>classes</parallel>
    <threadCount>${parallel.tests}</threadCount>
    <forkCount>${parallel.tests}</forkCount>
    <perCoreThreadCount>true</perCoreThreadCount>  
<!--    <skip>true</skip>  -->
    </configuration>    
</plugin>

And when I have the threadCount as say 3, and execute mvn clean verify serenity:aggregate I get the following logs

Start
Start
Stop
Stop
Start
Stop

What I am Expecting is

Start
Stop
Start
Stop
Start
Stop
  • Did you look up the effect of `forkCount` in the maven documentation? – M.P. Korstanje Jul 24 '19 at 16:08
  • Thanks @mpkorstanje The ```forkCount``` is equal to the max number of JVMs that the plugin uses to run the tests. After i changed the ```forkCount``` to 1, i got my expected result – sudarsunperu Jul 25 '19 at 07:59

1 Answers1

0

Set the forkCount to 1 and only 1 JVM will be used by the plugin to execute the tests. If more than 1 then multiple JVMs will be used and hence different synchronized static method will be used.

Reference: https://maven.apache.org/surefire/maven-surefire-plugin/examples/fork-options-and-parallel-execution.html