@Test and @BeforeMethod/@AfterMethod run in different thread?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

@Test and @BeforeMethod/@AfterMethod run in different thread?

manishnitjsr99
Hi All,

I see that if I have @BeforeMethod @Test and @AfterMethod, and if running in parallel methods, then I see there are 2 thread id - one for @BeforeMethod and @AfterMethod and another for @Test 

Is there a way so that entire flow of related methods - @BeforeMethod @Test and @AfterMethod - are in same thread?

Thanks,
Manish

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: @Test and @BeforeMethod/@AfterMethod run in different thread?

Krishnan Mahadevan
Manish,

Do you have a sample which can show this behavior ?

I can't simulate the problem on TestNG 6.9.11. If you look at the output you would notice that for each of the @Test methods [ I have two], the @BeforeMethod and @AfterMethod run on the same thread.

Here's my test class, my xml file and the output.

import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class BeforeMethodTestMethodThreadId {
@BeforeMethod
public void beforeMethod() {
printer("beforeMethod");
}

@Test
public void testMethod() {
printer("testMethod");
}

@Test
public void anotherTestMethod() {
printer("anotherTestMethod");
}

@AfterMethod
public void afterMethod() {
printer("afterMethod");
}

private void printer(String methodName) {
String msg = String.format("%s() is running on Thread id [%d]", methodName, Thread.currentThread().getId());
System.err.println("[DEBUGGER] :" + msg);

}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Class1Suite" parallel="methods" verbose="2">
<test name="Class1Test">
<classes>
<class name="organized.chaos.forums.BeforeMethodTestMethodThreadId"/>
</classes>
</test> <!-- Class1Test -->
</suite> <!-- Class1Suite -->

...
... TestNG 6.9.11 by Cédric Beust ([hidden email])
...

[TestNG] Running:
  /Users/krmahadevan/githome/PlayGround/testbed/src/test/resources/before-test-after-method.xml
[TestRunner] Starting executor for test Class1Test with time out:2147483647 milliseconds.

[DEBUGGER] :beforeMethod() is running on Thread id [10]
[DEBUGGER] :beforeMethod() is running on Thread id [9]
[DEBUGGER] :testMethod() is running on Thread id [10]
[DEBUGGER] :anotherTestMethod() is running on Thread id [9]
[DEBUGGER] :afterMethod() is running on Thread id [10]
[DEBUGGER] :afterMethod() is running on Thread id [9]

===============================================
Class1Suite
Total tests run: 2, Failures: 0, Skips: 0
===============================================


Process finished with exit code 0



Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

On Mon, May 16, 2016 at 9:43 PM, <[hidden email]> wrote:
Hi All,

I see that if I have @BeforeMethod @Test and @AfterMethod, and if running in parallel methods, then I see there are 2 thread id - one for @BeforeMethod and @AfterMethod and another for @Test 

Is there a way so that entire flow of related methods - @BeforeMethod @Test and @AfterMethod - are in same thread?

Thanks,
Manish

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: @Test and @BeforeMethod/@AfterMethod run in different thread?

manishnitjsr99
In reply to this post by manishnitjsr99
Thanks Krishnan.

I realised that the issue I had was due to timeOut in my suite in testng.xml

Thanks,
manish

On Monday, May 16, 2016 at 10:03:56 PM UTC+5:30, [hidden email] wrote:
Hi All,

I see that if I have @BeforeMethod @Test and @AfterMethod, and if running in parallel methods, then I see there are 2 thread id - one for @BeforeMethod and @AfterMethod and another for @Test 

Is there a way so that entire flow of related methods - @BeforeMethod @Test and @AfterMethod - are in same thread?

Thanks,
Manish

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: @Test and @BeforeMethod/@AfterMethod run in different thread?

Jeff Clyne
Thanks for following up on your own post with the solution. You saved me quite the headache!

On Wednesday, May 18, 2016 at 7:24:34 AM UTC-7, [hidden email] wrote:
Thanks Krishnan.

I realised that the issue I had was due to timeOut in my suite in testng.xml

Thanks,
manish

On Monday, May 16, 2016 at 10:03:56 PM UTC+5:30, [hidden email] wrote:
Hi All,

I see that if I have @BeforeMethod @Test and @AfterMethod, and if running in parallel methods, then I see there are 2 thread id - one for @BeforeMethod and @AfterMethod and another for @Test 

Is there a way so that entire flow of related methods - @BeforeMethod @Test and @AfterMethod - are in same thread?

Thanks,
Manish

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: @Test and @BeforeMethod/@AfterMethod run in different thread?

zoomout
In reply to this post by manishnitjsr99
It is still a problem in version 6.10. Had to figure it out by myself and spent a lot of time. And only afterwards checked this group for this topic =(

On Monday, May 16, 2016 at 6:33:56 PM UTC+2, [hidden email] wrote:
Hi All,

I see that if I have @BeforeMethod @Test and @AfterMethod, and if running in parallel methods, then I see there are 2 thread id - one for @BeforeMethod and @AfterMethod and another for @Test 

Is there a way so that entire flow of related methods - @BeforeMethod @Test and @AfterMethod - are in same thread?

Thanks,
Manish

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: @Test and @BeforeMethod/@AfterMethod run in different thread?

Julien Herr
Could be related to https://github.com/cbeust/testng/issues/914
Timeout uses a theadpool aka another new thread. 

Le lundi 2 janvier 2017 17:58:51 UTC+1, zoomout a écrit :
It is still a problem in version 6.10. Had to figure it out by myself and spent a lot of time. And only afterwards checked this group for this topic =(

On Monday, May 16, 2016 at 6:33:56 PM UTC+2, [hidden email] wrote:
Hi All,

I see that if I have @BeforeMethod @Test and @AfterMethod, and if running in parallel methods, then I see there are 2 thread id - one for @BeforeMethod and @AfterMethod and another for @Test 

Is there a way so that entire flow of related methods - @BeforeMethod @Test and @AfterMethod - are in same thread?

Thanks,
Manish

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: @Test and @BeforeMethod/@AfterMethod run in different thread?

er.sunainagrewal
In reply to this post by manishnitjsr99
Hi but if @Test is disabled will the @BeforeMethod still run?


On Monday, May 16, 2016 at 9:33:56 AM UTC-7, [hidden email] wrote:
Hi All,

I see that if I have @BeforeMethod @Test and @AfterMethod, and if running in parallel methods, then I see there are 2 thread id - one for @BeforeMethod and @AfterMethod and another for @Test 

Is there a way so that entire flow of related methods - @BeforeMethod @Test and @AfterMethod - are in same thread?

Thanks,
Manish

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: @Test and @BeforeMethod/@AfterMethod run in different thread?

Krishnan Mahadevan

What happens when you tried doing it?

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

Reply-To: <[hidden email]>
Date: Friday, April 6, 2018 at 3:32 AM
To: testng-users <[hidden email]>
Subject: [testng-users] Re: @Test and @BeforeMethod/@AfterMethod run in different thread?

 

Hi but if @Test is disabled will the @BeforeMethod still run?



On Monday, May 16, 2016 at 9:33:56 AM UTC-7, [hidden email] wrote:

Hi All,

 

I see that if I have @BeforeMethod @Test and @AfterMethod, and if running in parallel methods, then I see there are 2 thread id - one for @BeforeMethod and @AfterMethod and another for @Test 

 

Is there a way so that entire flow of related methods - @BeforeMethod @Test and @AfterMethod - are in same thread?

 

Thanks,

Manish

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
[hidden email].
To post to this group, send email to
[hidden email].
Visit this group at
https://groups.google.com/group/testng-users.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.