findinpath commented on a change in pull request #407:
URL: https://github.com/apache/maven-surefire/pull/407#discussion_r768888552
##########
File path:
surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java
##########
@@ -137,6 +152,31 @@ static void run( Iterable<Class<?>> testClasses, String
testSourceDirectory,
testng.run();
}
+ private static void addXmlClass( List<XmlClass> xmlClasses, String
testClassName )
+ {
+ XmlClass xmlClass = new XmlClass( testClassName );
+ if ( XML_CLASS_SET_INDEX != null )
+ {
+ try
+ {
+ // In case of parallel test execution with parallel="methods",
TestNG orders test execution
+ // by XmlClass.m_index field. When unset (equal for all
XmlClass instances), TestNG can
+ // invoke `@BeforeClass` setup methods on many instances,
without invoking `@AfterClass`
+ // tearDown methods, thus leading to high resource
consumptions when test instances
+ // allocate resources.
+ // With index set, order of setup, test and tearDown methods
is reasonable, with approximately
+ // #thread-count many test classes being initialized at given
point in time.
+ // Note: XmlClass.m_index field is set automatically by TestNG
when it reads a suite file.
+ XML_CLASS_SET_INDEX.invoke( xmlClass, xmlClasses.size() );
+ }
+ catch ( ReflectiveOperationException e )
+ {
+ throw new RuntimeException( e );
+ }
+ }
Review comment:
shouldn't we have here reflective access for the `m_index` field as well?
Instead of setting the `m_index` via reflection we could use the appropriate
constructor to set it:
- `XmlClass(String className, int index, boolean loadClasses)` in testng 5.x
- `XmlClass(String className, int index, boolean loadClasses)` in tesng 7.x
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]