Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

surefire-plugin does not respect threadCount parameter

Since several days, I tried to see where is my mistake in my configuration to run in parallel my Selenium tests.

I have a Selenium Grid with 2 nodes. In my pom.xml, I have set surefire to run 2 by 2 the methods of my tests with a particular category then other tests.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.18.1</version>
            <executions>
                <execution>
                    <id>default-test</id>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <parallel>methods</parallel>
                        <perCoreThreadCount>false</perCoreThreadCount>

                        <threadCount>2</threadCount>
                        <reuseForks>false</reuseForks>
                        <groups>
                            com.something.categories.Safe,
                            com.something.categories.Parallel
                        </groups>
                    </configuration>
                </execution>
                <execution>
                    <id>no-safe</id>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <excludedGroups>
                            com.something.categories.Safe,
                            com.something.Parallel
                        </excludedGroups>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

When I launch my test mvn clean test -Dtest='TestAwesome' all the tests contains in TestAwesome are launched in the same time (I see more than 2 browsers opended), and so does not respect my threadCount value.

I'm missing something?

Edition after answer Here my partial pom.xml to solve my issue

<profiles>
    <profile>
        <id>selenium-tests</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.18.1</version>
                    <configuration>
                        <parallel>all</parallel>
                        <threadCount>${threads}</threadCount>
                        <perCoreThreadCount>false</perCoreThreadCount>
                        <useUnlimitedThreads>true</useUnlimitedThreads>
                        <systemProperties>
                            <browser>${browser}</browser>
                            <screenshotDirectory>${project.build.directory}/screenshots</screenshotDirectory>
                            <gridURL>${seleniumGridURL}</gridURL>
                            <env>${env}</env>
                        </systemProperties>
                        <groups>${groups}</groups>
                        <excludedGroups>${excludedGroups}</excludedGroups>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>
like image 538
tetienne Avatar asked Oct 31 '22 23:10

tetienne


1 Answers

Since you are using a modern-enough version of surefire, you might wanna try the threadCountMethods parameter instead of threadCount in combination with useUnlimitedThreads = true, even though it seems counter-intuitive.

surefire jUnit examples:

As of Surefire 2.7, no additional dependencies are needed to use the full set of options with parallel. As of Surefire 2.16, new thread-count attributes are introduced, namely threadCountSuites, threadCountClasses and threadCountMethods.

Fork options and parallel execution:

As an example with an unlimited number of threads, there is maximum of three concurrent threads to execute suites: parallel = all, useUnlimitedThreads = true, threadCountSuites = 3.

like image 98
Carsten Avatar answered Nov 18 '22 22:11

Carsten