[ 
https://issues.apache.org/jira/browse/SUREFIRE-1535?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16592697#comment-16592697
 ] 

ASF GitHub Bot commented on SUREFIRE-1535:
------------------------------------------

asfgit closed pull request #190: [SUREFIRE-1535] Surefire unable to run testng 
suites in parallel
URL: https://github.com/apache/maven-surefire/pull/190
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java
 
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java
index 97140efa9..9c501db29 100644
--- 
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java
+++ 
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java
@@ -36,6 +36,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Collections;
 import java.util.List;
 
 import static 
org.apache.maven.surefire.booter.AbstractPathConfiguration.CHILD_DELEGATION;
@@ -125,7 +126,14 @@ File serialize( KeyValueSource sourceProperties, 
ProviderConfiguration booterCon
         if ( testSuiteDefinition != null )
         {
             properties.setProperty( SOURCE_DIRECTORY, 
testSuiteDefinition.getTestSourceDirectory() );
-            properties.addList( testSuiteDefinition.getSuiteXmlFiles(), 
TEST_SUITE_XML_FILES );
+            if ( testSet instanceof File )
+            {
+                properties.addList( Collections.singletonList( (File) testSet 
), TEST_SUITE_XML_FILES );
+            }
+            else
+            {
+                properties.addList( testSuiteDefinition.getSuiteXmlFiles(), 
TEST_SUITE_XML_FILES );
+            }
             TestListResolver testFilter = 
testSuiteDefinition.getTestListResolver();
             properties.setProperty( REQUESTEDTEST, testFilter == null ? "" : 
testFilter.getPluginParameterTest() );
             int rerunFailingTestsCount = 
testSuiteDefinition.getRerunFailingTestsCount();
diff --git 
a/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1535TestNGParallelSuitesIT.java
 
b/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1535TestNGParallelSuitesIT.java
new file mode 100644
index 000000000..3e4b0f2e1
--- /dev/null
+++ 
b/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1535TestNGParallelSuitesIT.java
@@ -0,0 +1,62 @@
+package org.apache.maven.surefire.its.jiras;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+
+import org.apache.maven.surefire.its.fixture.OutputValidator;
+import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class Surefire1535TestNGParallelSuitesIT extends 
SurefireJUnit4IntegrationTestCase
+{
+    @Test
+    public void testParallelSuites() throws Exception 
+    {
+        File tmp1 = null;
+        File tmp2 = null;
+        try
+        {
+            tmp1 = File.createTempFile( getClass().getName(), "tmp" );
+            tmp2 = File.createTempFile( getClass().getName(), "tmp" );
+            OutputValidator validator = 
unpack("/surefire-1535-parallel-testng").maven()
+                    .sysProp( "testNgVersion", "5.7" )
+                    .sysProp( "testNgClassifier", "jdk15" )
+                    .sysProp( "it.ParallelTest1", tmp1.getAbsolutePath() )
+                    .sysProp( "it.ParallelTest2", tmp2.getAbsolutePath() )
+                    .executeTest();
+            Assert.assertFalse(tmp1.exists());
+            Assert.assertFalse(tmp2.exists());
+            validator.assertTestSuiteResults( 2, 0, 0, 0 );
+        }
+        finally
+        {
+            if (tmp1 != null)
+            {
+                tmp1.delete();
+            }
+            if (tmp2 != null)
+            {
+                tmp2.delete();
+            }
+        }
+    }
+}
diff --git 
a/surefire-its/src/test/resources/surefire-1535-parallel-testng/pom.xml 
b/surefire-its/src/test/resources/surefire-1535-parallel-testng/pom.xml
new file mode 100644
index 000000000..942ddb631
--- /dev/null
+++ b/surefire-its/src/test/resources/surefire-1535-parallel-testng/pom.xml
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>org.apache.maven.plugins.surefire</groupId>
+    <artifactId>surefire-1535-parallel-testng</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <name>Test execution testng suites in parallel</name>
+
+    <properties>
+        <maven.compiler.source>1.6</maven.compiler.source>
+        <maven.compiler.target>1.6</maven.compiler.target>
+    </properties>
+
+    <profiles>
+        <profile>
+            <id>testng-old</id>
+            <activation>
+                <property><name>testNgClassifier</name></property>
+            </activation>
+            <dependencies>
+                <dependency>
+                    <groupId>org.testng</groupId>
+                    <artifactId>testng</artifactId>
+                    <version>${testNgVersion}</version>
+                    <classifier>${testNgClassifier}</classifier>
+                </dependency>
+            </dependencies>
+        </profile>
+        <profile>
+            <id>testng-new</id>
+            <activation>
+                <property><name>!testNgClassifier</name></property>
+            </activation>
+            <dependencies>
+                <dependency>
+                    <groupId>org.testng</groupId>
+                    <artifactId>testng</artifactId>
+                    <version>${testNgVersion}</version>
+                </dependency>
+            </dependencies>
+        </profile>
+    </profiles>
+
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <version>${surefire.version}</version>
+                <configuration>
+                    <forkCount>2</forkCount>
+                    <reuseForks>false</reuseForks>
+                    <suiteXmlFiles>
+                        
<suiteXmlFile>src/test/resources/Suite1.xml</suiteXmlFile>
+                        
<suiteXmlFile>src/test/resources/Suite2.xml</suiteXmlFile>
+                    </suiteXmlFiles>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
diff --git 
a/surefire-its/src/test/resources/surefire-1535-parallel-testng/src/test/java/it/ParallelTest.java
 
b/surefire-its/src/test/resources/surefire-1535-parallel-testng/src/test/java/it/ParallelTest.java
new file mode 100644
index 000000000..cd7a06cfb
--- /dev/null
+++ 
b/surefire-its/src/test/resources/surefire-1535-parallel-testng/src/test/java/it/ParallelTest.java
@@ -0,0 +1,46 @@
+package it;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+public class ParallelTest {
+
+    protected final boolean deleteFile() throws Exception
+    {
+        return deleteFile( getClass().getName() );
+    }
+
+    protected final boolean deleteFile( final String propName ) throws 
Exception
+    {
+        File temp = new File( AccessController.doPrivileged( new 
PrivilegedAction<String>()
+        {
+            @Override
+            public String run()
+            {
+                return System.getProperty( propName );
+            }
+        } ) );
+        return temp.delete();
+    }
+
+}
diff --git 
a/surefire-its/src/test/resources/surefire-1535-parallel-testng/src/test/java/it/ParallelTest1.java
 
b/surefire-its/src/test/resources/surefire-1535-parallel-testng/src/test/java/it/ParallelTest1.java
new file mode 100644
index 000000000..b9b9c98f1
--- /dev/null
+++ 
b/surefire-its/src/test/resources/surefire-1535-parallel-testng/src/test/java/it/ParallelTest1.java
@@ -0,0 +1,34 @@
+package it;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+@Test
+public class ParallelTest1 extends ParallelTest
+{
+
+    public void test() throws Exception
+    {
+        Assert.assertTrue( deleteFile() );
+    }
+
+}
diff --git 
a/surefire-its/src/test/resources/surefire-1535-parallel-testng/src/test/java/it/ParallelTest2.java
 
b/surefire-its/src/test/resources/surefire-1535-parallel-testng/src/test/java/it/ParallelTest2.java
new file mode 100644
index 000000000..158e6dc44
--- /dev/null
+++ 
b/surefire-its/src/test/resources/surefire-1535-parallel-testng/src/test/java/it/ParallelTest2.java
@@ -0,0 +1,34 @@
+package it;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+@Test
+public class ParallelTest2 extends ParallelTest
+{
+
+    public void test() throws Exception
+    {
+        Assert.assertTrue( deleteFile() );
+    }
+
+}
diff --git 
a/surefire-its/src/test/resources/surefire-1535-parallel-testng/src/test/resources/Suite1.xml
 
b/surefire-its/src/test/resources/surefire-1535-parallel-testng/src/test/resources/Suite1.xml
new file mode 100644
index 000000000..b6ca16bd6
--- /dev/null
+++ 
b/surefire-its/src/test/resources/surefire-1535-parallel-testng/src/test/resources/Suite1.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"; >
+
+<suite name="Suite1" verbose="5">
+    <test name="Suite1">
+        <classes>
+            <class name="it.ParallelTest1" />
+        </classes>
+    </test>
+</suite>
\ No newline at end of file
diff --git 
a/surefire-its/src/test/resources/surefire-1535-parallel-testng/src/test/resources/Suite2.xml
 
b/surefire-its/src/test/resources/surefire-1535-parallel-testng/src/test/resources/Suite2.xml
new file mode 100644
index 000000000..aef1754f6
--- /dev/null
+++ 
b/surefire-its/src/test/resources/surefire-1535-parallel-testng/src/test/resources/Suite2.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"; >
+
+<suite name="Suite2" verbose="5">
+    <test name="Suite2">
+        <classes>
+            <class name="it.ParallelTest2" />
+        </classes>
+    </test>
+</suite>
\ No newline at end of file


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Surefire unable to run testng suites in parallel
> ------------------------------------------------
>
>                 Key: SUREFIRE-1535
>                 URL: https://issues.apache.org/jira/browse/SUREFIRE-1535
>             Project: Maven Surefire
>          Issue Type: Bug
>          Components: TestNG support
>    Affects Versions: 2.22.0
>            Reporter: Andrey Panfilov
>            Assignee: Tibor Digana
>            Priority: Minor
>             Fix For: 2.22.1
>
>
> Due to slowness nature of selenium test we would like to run such tests in 
> parallel, moreover, we also would like to avoid thread-safety issues, so our 
> option is to take advantage of  forkCount=N and reuseForks=false instead of 
> using built-in testng capabilities. Unfortunately, when using following maven 
> configuration:
> {code:java}
> <forkCount>2</forkCount>
> <reuseForks>false</reuseForks>
> <suiteXmlFiles>
>     <suiteXmlFile>Suite_1.xml</suiteXmlFile>
>     <suiteXmlFile>Suite_2.xml</suiteXmlFile>
> </suiteXmlFiles>
> {code}
> it does not work like expected, i.e.:
>  * ForkStarter#runSuitesForkPerTestSet correctly spawns multiple JVMs and 
> passes individual testng suite to ForkStarter#fork
>  * TestNGProvider#invoke fails to cover the case that forkTestSet could be a 
> file and runs all testng suites instead of individual one.
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to