Skip to content

Commit 0400664

Browse files
committed
Abort for invalid combinations
GraphThreadPoolExecutor will NOT work if user is trying to use a shared thread pool for just their data driven tests (or) for all tests (both regular and data driven) . So if these combinations are found, abort execution.
1 parent d01a4f1 commit 0400664

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

testng-core/src/main/java/org/testng/TestNG.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,9 +1209,11 @@ public List<ISuite> runSuitesLocally() {
12091209
// Create a map with XmlSuite as key and corresponding SuiteRunner as value
12101210
for (XmlSuite xmlSuite : m_suites) {
12111211
if (m_configuration.isShareThreadPoolForDataProviders()) {
1212+
abortIfUsingGraphThreadPoolExecutor("Shared thread-pool for data providers");
12121213
xmlSuite.setShareThreadPoolForDataProviders(true);
12131214
}
12141215
if (m_configuration.useGlobalThreadPool()) {
1216+
abortIfUsingGraphThreadPoolExecutor("Global thread-pool");
12151217
xmlSuite.shouldUseGlobalThreadPool(true);
12161218
}
12171219
createSuiteRunners(suiteRunnerMap, xmlSuite);
@@ -1262,6 +1264,13 @@ private static void error(String s) {
12621264
LOGGER.error(s);
12631265
}
12641266

1267+
private static void abortIfUsingGraphThreadPoolExecutor(String prefix) {
1268+
if (RuntimeBehavior.favourCustomThreadPoolExecutor()) {
1269+
throw new UnsupportedOperationException(
1270+
prefix + " is NOT COMPATIBLE with TestNG's custom thread pool executor");
1271+
}
1272+
}
1273+
12651274
/**
12661275
* @return the verbose level, checking in order: the verbose level on the suite, the verbose level
12671276
* on the TestNG object, or 1.

testng-core/src/test/java/test/dataprovider/DataProviderTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.testng.annotations.DataProvider;
1919
import org.testng.annotations.Test;
2020
import org.testng.collections.Lists;
21+
import org.testng.internal.RuntimeBehavior;
2122
import org.testng.internal.collections.Pair;
2223
import org.testng.internal.reflect.MethodMatcherException;
2324
import org.testng.xml.XmlClass;
@@ -609,6 +610,20 @@ public void ensureSequentialDataProviderWithRetryAnalyserWorks() {
609610
runTest(false);
610611
}
611612

613+
@Test(
614+
description = "GITHUB-2980",
615+
expectedExceptions = UnsupportedOperationException.class,
616+
expectedExceptionsMessageRegExp =
617+
"Shared thread-pool for data providers is NOT COMPATIBLE with TestNG's custom thread pool executor")
618+
public void ensureErrorShownWhenUsedWithGraphThreadPoolExecutor() {
619+
try {
620+
System.setProperty(RuntimeBehavior.FAVOR_CUSTOM_THREAD_POOL_EXECUTOR, "true");
621+
runDataProviderTest(true);
622+
} finally {
623+
System.setProperty(RuntimeBehavior.FAVOR_CUSTOM_THREAD_POOL_EXECUTOR, "false");
624+
}
625+
}
626+
612627
@Test(description = "GITHUB-2980", dataProvider = "dataProviderForIssue2980")
613628
public void ensureWeCanShareThreadPoolForDataProviders(
614629
boolean flag, Pair<List<String>, Integer> pair) {

testng-core/src/test/java/test/thread/SharedThreadPoolTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.testng.TestNG;
1010
import org.testng.annotations.AfterMethod;
1111
import org.testng.annotations.Test;
12+
import org.testng.internal.RuntimeBehavior;
1213
import org.testng.xml.XmlSuite;
1314
import test.SimpleBaseTest;
1415
import test.thread.issue2019.TestClassSample;
@@ -37,6 +38,20 @@ public void ensureCommonThreadPoolIsNotUsed() {
3738
.hasSizeGreaterThanOrEqualTo(3);
3839
}
3940

41+
@Test(
42+
description = "GITHUB-2019",
43+
expectedExceptions = UnsupportedOperationException.class,
44+
expectedExceptionsMessageRegExp =
45+
"Global thread-pool is NOT COMPATIBLE with TestNG's custom thread pool executor")
46+
public void ensureErrorShownWhenUsedWithGraphThreadPoolExecutor() {
47+
try {
48+
System.setProperty(RuntimeBehavior.FAVOR_CUSTOM_THREAD_POOL_EXECUTOR, "true");
49+
runSimpleTest(true);
50+
} finally {
51+
System.setProperty(RuntimeBehavior.FAVOR_CUSTOM_THREAD_POOL_EXECUTOR, "false");
52+
}
53+
}
54+
4055
private static List<Long> runSimpleTest(boolean useSharedGlobalThreadPool) {
4156
TestNG testng = create(TestClassSample.class);
4257
testng.shouldUseGlobalThreadPool(useSharedGlobalThreadPool);

0 commit comments

Comments
 (0)