From 2cf4674e75df0a9d5ea8396c429e5972676641dd Mon Sep 17 00:00:00 2001 From: Scott Babcock Date: Sun, 24 Apr 2022 23:54:17 -0700 Subject: [PATCH] [SUREFIRE-2075] Only set thread count if spec'd --- .../its/CheckTestNg740ParallelIT.java | 8 ++ .../pom.xml | 73 +++++++++++++++++++ .../java/testng740/TestNG740ParallelTest.java | 35 +++++++++ .../testng/conf/TestNGMapConfigurator.java | 16 +++- 4 files changed, 128 insertions(+), 4 deletions(-) create mode 100644 surefire-its/src/test/resources/testng-740-parallel-without-threadcount/pom.xml create mode 100644 surefire-its/src/test/resources/testng-740-parallel-without-threadcount/src/test/java/testng740/TestNG740ParallelTest.java diff --git a/surefire-its/src/test/java/org/apache/maven/surefire/its/CheckTestNg740ParallelIT.java b/surefire-its/src/test/java/org/apache/maven/surefire/its/CheckTestNg740ParallelIT.java index 70741ece0b..2122e91a53 100644 --- a/surefire-its/src/test/java/org/apache/maven/surefire/its/CheckTestNg740ParallelIT.java +++ b/surefire-its/src/test/java/org/apache/maven/surefire/its/CheckTestNg740ParallelIT.java @@ -35,4 +35,12 @@ public void withTestNG740AndParallelSet() .executeTest() .assertTestSuiteResults( 2, 0, 0, 0 ); } + + @Test + public void withTestNG740AndParallelSetWithoutThreadCount() + { + unpack( "testng-740-parallel-without-threadcount" ) + .executeTest() + .assertTestSuiteResults( 2, 0, 0, 0 ); + } } diff --git a/surefire-its/src/test/resources/testng-740-parallel-without-threadcount/pom.xml b/surefire-its/src/test/resources/testng-740-parallel-without-threadcount/pom.xml new file mode 100644 index 0000000000..3ebb853089 --- /dev/null +++ b/surefire-its/src/test/resources/testng-740-parallel-without-threadcount/pom.xml @@ -0,0 +1,73 @@ + + + + + 4.0.0 + + org.apache.maven.plugins.surefire + testng-740-parallel + 1.0-SNAPSHOT + TestNG 7.4.0 parallel test + + + 0 + + + 1.7 + 1.7 + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.version} + + ${argLine} ${jacoco.agent} + methods + + + surefire.testng.verbose + ${surefire.testng.verbose} + + + + + + + + + org.testng + testng + 7.4.0 + + + + junit + junit + + + + + + diff --git a/surefire-its/src/test/resources/testng-740-parallel-without-threadcount/src/test/java/testng740/TestNG740ParallelTest.java b/surefire-its/src/test/resources/testng-740-parallel-without-threadcount/src/test/java/testng740/TestNG740ParallelTest.java new file mode 100644 index 0000000000..855b92fa05 --- /dev/null +++ b/surefire-its/src/test/resources/testng-740-parallel-without-threadcount/src/test/java/testng740/TestNG740ParallelTest.java @@ -0,0 +1,35 @@ +package testng.simple; + +/* + * 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.annotations.Test; + + +public class TestNG740ParallelTest { + @Test + public void testOne() { + + } + + @Test + public void testTwo() { + + } +} diff --git a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java index 186110d691..874e7f1f3c 100755 --- a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java +++ b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java @@ -28,7 +28,6 @@ import org.testng.TestNG; import org.testng.xml.XmlSuite; -import static java.lang.Integer.parseInt; import static org.apache.maven.surefire.api.booter.ProviderParameterNames.PARALLEL_PROP; import static org.apache.maven.surefire.api.booter.ProviderParameterNames.THREADCOUNT_PROP; import static org.apache.maven.surefire.testng.conf.AbstractDirectConfigurator.loadListenerClasses; @@ -68,9 +67,18 @@ public void configure( XmlSuite suite, Map options ) protected void configureThreadCount( XmlSuite suite, Map options ) throws TestSetFailedException { - String threadCountAsString = options.get( THREADCOUNT_PROP ); - int threadCount = threadCountAsString == null ? 1 : parseInt( threadCountAsString ); - suite.setThreadCount( threadCount ); + String threadCount = options.get( THREADCOUNT_PROP ); + if ( threadCount != null ) + { + try + { + suite.setThreadCount( Integer.parseInt( threadCount ) ); + } + catch ( NumberFormatException e ) + { + throw new TestSetFailedException( "Non-integer TestNG [threadcount] setting: " + threadCount, e ); + } + } } protected void configureParallel( XmlSuite suite, Map options )