diff --git a/testng-core/src/main/java/org/testng/TestNG.java b/testng-core/src/main/java/org/testng/TestNG.java index f91fa6865..cda2756a8 100644 --- a/testng-core/src/main/java/org/testng/TestNG.java +++ b/testng-core/src/main/java/org/testng/TestNG.java @@ -1209,9 +1209,11 @@ public List runSuitesLocally() { // Create a map with XmlSuite as key and corresponding SuiteRunner as value for (XmlSuite xmlSuite : m_suites) { if (m_configuration.isShareThreadPoolForDataProviders()) { + abortIfUsingGraphThreadPoolExecutor("Shared thread-pool for data providers"); xmlSuite.setShareThreadPoolForDataProviders(true); } if (m_configuration.useGlobalThreadPool()) { + abortIfUsingGraphThreadPoolExecutor("Global thread-pool"); xmlSuite.shouldUseGlobalThreadPool(true); } createSuiteRunners(suiteRunnerMap, xmlSuite); @@ -1262,6 +1264,13 @@ private static void error(String s) { LOGGER.error(s); } + private static void abortIfUsingGraphThreadPoolExecutor(String prefix) { + if (RuntimeBehavior.favourCustomThreadPoolExecutor()) { + throw new UnsupportedOperationException( + prefix + " is NOT COMPATIBLE with TestNG's custom thread pool executor"); + } + } + /** * @return the verbose level, checking in order: the verbose level on the suite, the verbose level * on the TestNG object, or 1. diff --git a/testng-core/src/test/java/test/dataprovider/DataProviderTest.java b/testng-core/src/test/java/test/dataprovider/DataProviderTest.java index bda5a9846..d2e75595f 100644 --- a/testng-core/src/test/java/test/dataprovider/DataProviderTest.java +++ b/testng-core/src/test/java/test/dataprovider/DataProviderTest.java @@ -18,6 +18,7 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import org.testng.collections.Lists; +import org.testng.internal.RuntimeBehavior; import org.testng.internal.collections.Pair; import org.testng.internal.reflect.MethodMatcherException; import org.testng.xml.XmlClass; @@ -609,6 +610,20 @@ public void ensureSequentialDataProviderWithRetryAnalyserWorks() { runTest(false); } + @Test( + description = "GITHUB-2980", + expectedExceptions = UnsupportedOperationException.class, + expectedExceptionsMessageRegExp = + "Shared thread-pool for data providers is NOT COMPATIBLE with TestNG's custom thread pool executor") + public void ensureErrorShownWhenUsedWithGraphThreadPoolExecutor() { + try { + System.setProperty(RuntimeBehavior.FAVOR_CUSTOM_THREAD_POOL_EXECUTOR, "true"); + runDataProviderTest(true); + } finally { + System.setProperty(RuntimeBehavior.FAVOR_CUSTOM_THREAD_POOL_EXECUTOR, "false"); + } + } + @Test(description = "GITHUB-2980", dataProvider = "dataProviderForIssue2980") public void ensureWeCanShareThreadPoolForDataProviders( boolean flag, Pair, Integer> pair) { diff --git a/testng-core/src/test/java/test/thread/SharedThreadPoolTest.java b/testng-core/src/test/java/test/thread/SharedThreadPoolTest.java index 8351bb227..5a31845fc 100644 --- a/testng-core/src/test/java/test/thread/SharedThreadPoolTest.java +++ b/testng-core/src/test/java/test/thread/SharedThreadPoolTest.java @@ -9,6 +9,7 @@ import org.testng.TestNG; import org.testng.annotations.AfterMethod; import org.testng.annotations.Test; +import org.testng.internal.RuntimeBehavior; import org.testng.xml.XmlSuite; import test.SimpleBaseTest; import test.thread.issue2019.TestClassSample; @@ -37,6 +38,20 @@ public void ensureCommonThreadPoolIsNotUsed() { .hasSizeGreaterThanOrEqualTo(3); } + @Test( + description = "GITHUB-2019", + expectedExceptions = UnsupportedOperationException.class, + expectedExceptionsMessageRegExp = + "Global thread-pool is NOT COMPATIBLE with TestNG's custom thread pool executor") + public void ensureErrorShownWhenUsedWithGraphThreadPoolExecutor() { + try { + System.setProperty(RuntimeBehavior.FAVOR_CUSTOM_THREAD_POOL_EXECUTOR, "true"); + runSimpleTest(true); + } finally { + System.setProperty(RuntimeBehavior.FAVOR_CUSTOM_THREAD_POOL_EXECUTOR, "false"); + } + } + private static List runSimpleTest(boolean useSharedGlobalThreadPool) { TestNG testng = create(TestClassSample.class); testng.shouldUseGlobalThreadPool(useSharedGlobalThreadPool);