Dependent methods not running in correct order when using parallel instances
See original GitHub issueTestNG version 7.3.0
Dependent methods might not always execute in the correct order with parallel=instances
, below is a reproducer, which quite often fails (not 100% reliable as sometimes does succeed too). Not sure why, but I could not reproduce it without the added delay. Also the number of test methods in the class had a relation to failures too.
Is this a known issue? It seems I cannot use parallel=instances
with dependent methods even if my code is thread safe if there are dependencies between test methods.
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Factory;
import org.testng.annotations.Test;
import java.util.concurrent.atomic.AtomicInteger;
import static org.testng.Assert.assertEquals;
@Test(suiteName = "testParallel")
public class TestNGParallelDependent {
private final String prefix;
private final int delay;
private final AtomicInteger counter = new AtomicInteger();
private volatile String value;
@Factory(dataProvider = "dp")
TestNGParallelDependent(String prefix, int delay) {
this.prefix = prefix;
this.delay = delay;
}
@DataProvider
static Object[][] dp() {
int instances = 3;
int delay = 1;
Object[][] params = new Object[instances][2];
for (int i = 0; i < instances; i++) {
params[i][0] = "v" + (i + 1);
params[i][1] = delay * 1000;
delay <<= 1;
}
return params;
}
@BeforeClass
void setup() {
work(delay);
}
@Test
void testA() {
assertEquals(1, counter.incrementAndGet());
}
@Test(dependsOnMethods = "testA")
void testB() {
assertEquals(2, counter.incrementAndGet());
}
@Test(dependsOnMethods = "testB")
void testC() {
assertEquals(3, counter.incrementAndGet());
}
@Test(dependsOnMethods = "testC")
void testD() {
assertEquals(4, counter.incrementAndGet());
}
@Test(dependsOnMethods = "testD")
void testE() {
assertEquals(5, counter.incrementAndGet());
}
@Test(dependsOnMethods = "testE")
void testF() {
assertEquals(6, counter.incrementAndGet());
}
@Test(dependsOnMethods = "testF")
void testG() {
assertEquals(7, counter.incrementAndGet());
}
@Test(dependsOnMethods = "testG")
void testH() {
assertEquals(8, counter.incrementAndGet());
}
@Test(dependsOnMethods = "testH")
void testI() {
assertEquals(9, counter.incrementAndGet());
}
@Test(dependsOnMethods = "testI")
void testJ() {
assertEquals(10, counter.incrementAndGet());
}
private static void work(int delay) {
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
_Originally posted by @mihalyr in https://github.com/cbeust/testng/issues/751#issuecomment-699694723_
Issue Analytics
- State:
- Created 3 years ago
- Comments:10
Top Results From Across the Web
java - Parallel(methods) execution with dependsOn running in ...
So the order of invocation is defined by you in the question but then the execution is not dependent on the success or...
Read more >Dependent methods in the same class run out of order only ...
Dependent methods in the same class run out of order only when included in a “testng suite”; running class independently respects the dependency....
Read more >Parallel Execution in Selenium: Session Handling & TestNG ...
Test cases in same instance will execute parallel but two methods of two different instances will run in different thread. The attribute thread- ......
Read more >What are TestNG Dependent Tests and How to ... - Tools QA
Often, we want to run our test cases in a particular order in TestNG. We may use the priority parameter for that, no...
Read more >Parallel Test Execution in Selenium using TestNG - H2k Infosys
Dependent methods will also run in separate threads in the specified order. parallel = “classes“: TestNG will run all the test methods in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes
7.4.0
will contain the changesYep, this is on
7.3.0
also, added to the description