allure-java
allure-java copied to clipboard
🐞: ClassCastException when using TestNG 7.9.0 with use-global-thread-pool="true"
What happened?
TestNg has recently released new version with a feature that allows using shared thread pool for all data driven and non data driven tests When using it with allure testng, the tests throws ClassCastException
Please see the examples attached
build.gradle
buildscript {
ext {
allureVersion = '2.25.0'
aspectjVersion = '1.9.21.1'
testngVersion = '7.9.0'
}
}
plugins {
id 'java'
id 'idea'
id "io.freefair.aspectj.post-compile-weaving" version "8.6"
id 'io.qameta.allure' version '2.11.2'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
implementation("org.testng:testng:$testngVersion")
implementation platform("io.qameta.allure:allure-bom:$allureVersion")
implementation("io.qameta.allure:allure-testng:$allureVersion")
implementation("org.aspectj:aspectjweaver:$aspectjVersion")
implementation("org.aspectj:aspectjrt:$aspectjVersion")
}
task runOneTest(type: Test) {
useTestNG() {
suites "src/test/resources/test_suites/allure_testng_test.xml"
}
}
test class
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.util.concurrent.ThreadLocalRandom;
public class AllureTestngTest {
private static final int dataSize = 25;
@Test(dataProvider = "dp")
public void parallelDataDrivenTest1(int i) {
}
@Test(dataProvider = "dp")
public void parallelDataDrivenTest2(int i) {
}
@DataProvider(name = "dp", parallel = true)
public Object[][] getData() {
Object[][] data = new Object[dataSize][1];
for (int i = 0; i < dataSize; i++) {
data[i][0] = ThreadLocalRandom.current().nextInt();
}
return data;
}
}
testng xml
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.1.dtd" >
<suite name="Example suite" parallel="methods" use-global-thread-pool="true" thread-count="4">
<test name="One Test">
<classes>
<class name="AllureTestngTest"/>
</classes>
</test>
</suite>
stack trace
class java.util.concurrent.CompletableFuture$AsyncSupply cannot be cast to class java.lang.Comparable (java.util.concurrent.CompletableFuture$AsyncSupply and java.lang.Comparable are in module java.base of loader 'bootstrap')
java.lang.ClassCastException: class java.util.concurrent.CompletableFuture$AsyncSupply cannot be cast to class java.lang.Comparable (java.util.concurrent.CompletableFuture$AsyncSupply and java.lang.Comparable are in module java.base of loader 'bootstrap')
at java.base/java.util.concurrent.PriorityBlockingQueue.siftUpComparable(PriorityBlockingQueue.java:349)
at java.base/java.util.concurrent.PriorityBlockingQueue.offer(PriorityBlockingQueue.java:475)
at java.base/java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1357)
at java.base/java.util.concurrent.CompletableFuture.asyncSupplyStage(CompletableFuture.java:1782)
at java.base/java.util.concurrent.CompletableFuture.supplyAsync(CompletableFuture.java:2005)
at org.testng.internal.invokers.MethodRunner.runInParallel(MethodRunner.java:143)
at org.testng.internal.invokers.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:950)
at org.testng.internal.invokers.TestInvoker.invokeTestMethods(TestInvoker.java:201)
at org.testng.internal.invokers.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:148)
at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.testng.internal.thread.graph.TestNGFutureTask.run(TestNGFutureTask.java:22)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)
What Allure Integration are you using?
allure-testng
What version of Allure Integration you are using?
2.25.0
What version of Allure Report you are using?
2.25.0
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
I have the same issue. All data driven tests are failing with this error
almost the same
<suite use-global-thread-pool="true" configfailurepolicy="continue" thread-count="100" parallel="tests" name="Test suite">
<test thread-count="100" parallel="methods" name="combined">
...
java.lang.ClassCastException: class org.testng.internal.thread.graph.TestNGFutureTask cannot be cast to class org.testng.internal.thread.Async$AsyncTask (org.testng.internal.thread.graph.TestNGFutureTask and org.testng.internal.thread.Async$AsyncTask are in unnamed module of loader 'app')
at org.testng.internal.thread.Async$AsyncTask.compareTo(Async.java:22)
at java.base/java.util.concurrent.PriorityBlockingQueue.siftUpComparable(PriorityBlockingQueue.java:353)
at java.base/java.util.concurrent.PriorityBlockingQueue.offer(PriorityBlockingQueue.java:475)
at java.base/java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1357)
at org.testng.internal.thread.Async.run(Async.java:18)
at org.testng.internal.invokers.MethodRunner.runInParallel(MethodRunner.java:143)
at org.testng.internal.invokers.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:981)
at org.testng.internal.invokers.TestInvoker.invokeTestMethods(TestInvoker.java:203)
at org.testng.internal.invokers.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:154)
at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:134)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.testng.internal.thread.graph.TestNGFutureTask.run(TestNGFutureTask.java:22)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:840)
I think the problem is in the TestNG: https://github.com/testng-team/testng/issues/3179