Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions testng-core/src/main/java/org/testng/TestNG.java
Original file line number Diff line number Diff line change
Expand Up @@ -1209,9 +1209,11 @@ public List<ISuite> 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);
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<List<String>, Integer> pair) {
Expand Down
15 changes: 15 additions & 0 deletions testng-core/src/test/java/test/thread/SharedThreadPoolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Long> runSimpleTest(boolean useSharedGlobalThreadPool) {
TestNG testng = create(TestClassSample.class);
testng.shouldUseGlobalThreadPool(useSharedGlobalThreadPool);
Expand Down