|
51 | 51 | import eu.tsystems.mms.tic.testframework.report.utils.ExecutionContextController; |
52 | 52 | import java.util.Date; |
53 | 53 | import java.util.Locale; |
| 54 | +import java.util.concurrent.ConcurrentHashMap; |
54 | 55 | import org.apache.logging.log4j.Level; |
55 | 56 | import org.apache.logging.log4j.core.LoggerContext; |
56 | 57 | import org.apache.logging.log4j.core.config.Configurator; |
|
75 | 76 | import org.testng.internal.InvokedMethod; |
76 | 77 | import org.testng.internal.TestResult; |
77 | 78 | import org.testng.xml.XmlSuite; |
78 | | - |
79 | 79 | import java.util.List; |
80 | | -import java.util.Locale; |
81 | 80 |
|
82 | 81 | /** |
83 | 82 | * Listener for JUnit and TestNg, collects test informations for testreport. |
@@ -117,6 +116,7 @@ public class TesterraListener implements |
117 | 116 | private static final Report report; |
118 | 117 | private static DefaultTestNGContextGenerator contextGenerator; |
119 | 118 | private static final TestStatusController testStatusController = new TestStatusController(); |
| 119 | + private static final ConcurrentHashMap<ITestNGMethod, Boolean> dataProviderSemaphore = new ConcurrentHashMap<>(); |
120 | 120 |
|
121 | 121 | static { |
122 | 122 | String logLevel = PropertyManager.getProperty("log4j.level"); |
@@ -524,14 +524,22 @@ public static boolean isActive() { |
524 | 524 |
|
525 | 525 | @Override |
526 | 526 | public void onDataProviderFailure(ITestNGMethod testNGMethod, ITestContext testContext, RuntimeException exception) { |
527 | | - TestResult testResult = TestResult.newContextAwareTestResult(testNGMethod, testContext); |
528 | | - InvokedMethod invokedMethod = new InvokedMethod(new Date().getTime(), testResult); |
529 | | - MethodContext methodContext = pBeforeInvocation(invokedMethod, testResult, testContext); |
530 | | - if (exception.getCause() != null) { |
531 | | - methodContext.addError(exception.getCause()); |
532 | | - } else { |
533 | | - methodContext.addError(exception); |
| 527 | + /** |
| 528 | + * TestNG calls the data provider initialization for every thread. |
| 529 | + * Added a semaphore to prevent adding multiple method contexts. |
| 530 | + */ |
| 531 | + if (!dataProviderSemaphore.containsKey(testNGMethod)) { |
| 532 | + TestResult testResult = TestResult.newContextAwareTestResult(testNGMethod, testContext); |
| 533 | + InvokedMethod invokedMethod = new InvokedMethod(new Date().getTime(), testResult); |
| 534 | + MethodContext methodContext = pBeforeInvocation(invokedMethod, testResult, testContext); |
| 535 | + if (exception.getCause() != null) { |
| 536 | + methodContext.addError(exception.getCause()); |
| 537 | + } else { |
| 538 | + methodContext.addError(exception); |
| 539 | + } |
| 540 | + pAfterInvocation(invokedMethod, testResult, testContext); |
| 541 | + |
| 542 | + dataProviderSemaphore.put(testNGMethod, true); |
534 | 543 | } |
535 | | - pAfterInvocation(invokedMethod, testResult, testContext); |
536 | 544 | } |
537 | 545 | } |
0 commit comments