Question about timeOut parameter inside a a @Test

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

Question about timeOut parameter inside a a @Test

Tsiakos, Panagiotis

Hi ,

I have a guestion about the timeOut parameter inside a @Test method  (

timeOut The maximum number of milliseconds this test should take.
)

saw that when the timeoout expires the test fails throwing a timeout exception and the main thread goes

to the next @Test (that is what I expected)

The problem is that I observed also that a second threard is spawned in parallel, that tries to execute the @Test with the expired timeout,

from the point that the timeout occurred. That really messes the execution of the @Test methods inside a test class.

Is this a bug or for some reason it works as designed?

Regards

Panagiotis

 

Panagiotis Tsiakos

Siemens Enterprise Communications S.A.

Enterprise Product Development
15 Andrea Metaxa str., Room 1.14

GR 145 64, Nea Kifisia
Athens, Greece
Tel: +30 210 8189609

Fax: +30 210 8189761
mailto: [hidden email]

 

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: Question about timeOut parameter inside a a @Test

Krishnan Mahadevan
Am not quite sure if I got this question right, but I ran a quick check and dont see a problem. Perhaps you can elaborate more with a demo class and provide the expected results Vs actual results that you are seeing along with the testng version that you are working with.

As expected only method1 failed for me and method2 passed.
Am working with TestNG eclipse plug-in version 6.3.0


Here's my sample test :
public class TestNGTimeOutDemo {
@Test(timeOut=1500)
public void method1() throws InterruptedException {
Thread.sleep(2000);
}

@Test
public void method2() throws InterruptedException {
Thread.sleep(2000);
Assert.assertTrue(true);
}
}

PASSED: method2

FAILED: method1

org.testng.internal.thread.ThreadTimeoutException: Method org.testng.internal.TestNGMethod.method1() didn't finish within the time-out 1500



Thanks & Regards
Krishnan Mahadevan

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


On Fri, Jan 27, 2012 at 5:29 PM, Tsiakos, Panagiotis <[hidden email]> wrote:

Hi ,

I have a guestion about the timeOut parameter inside a @Test method  (

timeOut The maximum number of milliseconds this test should take.
)

saw that when the timeoout expires the test fails throwing a timeout exception and the main thread goes

to the next @Test (that is what I expected)

The problem is that I observed also that a second threard is spawned in parallel, that tries to execute the @Test with the expired timeout,

from the point that the timeout occurred. That really messes the execution of the @Test methods inside a test class.

Is this a bug or for some reason it works as designed?

Regards

Panagiotis

 

Panagiotis Tsiakos

Siemens Enterprise Communications S.A.

Enterprise Product Development
15 Andrea Metaxa str., Room 1.14

GR 145 64, Nea Kifisia
Athens, Greece
Tel: <a href="tel:%2B30%20210%208189609" value="+302108189609" target="_blank">+30 210 8189609

Fax: +30 210 8189761
mailto: [hidden email]

 

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

RE: Question about timeOut parameter inside a a @Test

Tsiakos, Panagiotis
Hi Krishnan after investigation we concluded that the problem occurs when the TestNG timeOut takes place in a called method inside the @Test method
See below code for example. I would expect that the aMethod with arg b waits for ..   should not printed since it occurs after the timeout.
If aMethod does not catch the InterruptedException then everything works fine.
 
 
 
package com.testall;
 
import org.testng.annotations.Test;
 
public class A01_test1{
 
   @Test(priority = 1 , timeOut=5000)
   public void test1() throws InterruptedException {
    aMethod("a");
    aMethod("b");
    System.out.println("If you see this then is an ERROR");
   }
  
 @Test(priority = 2)
 public void test2() throws InterruptedException {
   System.out.println("Test2 start");
   Thread.sleep(10000);
   System.out.println("Test2 finsish");
 }
 
 public void aMethod(String argument){
  System.out.println("Method called with "+argument);
  int i=0;
   while(i<5){
     System.out.println("aMethod with arg "+ argument +" waits for "+i);
      try {
    Thread.sleep(1000);
   } catch (InterruptedException e) {
    e.printStackTrace();
   }
      i++;
    } 
 }
}
 
 
 
The output is as follows: (see red coloured lines)
 

[TestNG] [DEBUG] suiteXmlPath: "C:\DOCUME~1\grmssfq0\LOCALS~1\Temp\testng-eclipse--1900961393\testng-customsuite.xml"

[TestNG] Running:

C:\Documents and Settings\grmssfq0\Local Settings\Temp\testng-eclipse--1900961393\testng-customsuite.xml

Method called with a

aMethod with arg a waits for 0

aMethod with arg a waits for 1

aMethod with arg a waits for 2

aMethod with arg a waits for 3

aMethod with arg a waits for 4

Method called with b

aMethod with arg b waits for 0

java.lang.InterruptedException: sleep interrupted

Test2 start

at java.lang.Thread.sleep(Native Method)

at com.testall.A01_test1.aMethod(A01_test1.java:27)

at com.testall.A01_test1.test1(A01_test1.java:10)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)

at org.testng.internal.InvokeMethodRunnable.runOne(InvokeMethodRunnable.java:46)

at org.testng.internal.InvokeMethodRunnable.run(InvokeMethodRunnable.java:37)

at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)

at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)

at java.util.concurrent.FutureTask.run(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

aMethod with arg b waits for 1

aMethod with arg b waits for 2

aMethod with arg b waits for 3

aMethod with arg b waits for 4

If you see this then is an ERROR

Test2 finsish

PASSED: test2

FAILED: test1

org.testng.internal.thread.ThreadTimeoutException: Method org.testng.internal.TestNGMethod.test1() didn't finish within the time-out 5000

at java.lang.Throwable.getStackTraceElement(Native Method)

at java.lang.Throwable.getOurStackTrace(Throwable.java:591)

at java.lang.Throwable.printStackTrace(Throwable.java:462)

at java.lang.Throwable.printStackTrace(Throwable.java:451)

at com.testall.A01_test1.aMethod(A01_test1.java:29)

at com.testall.A01_test1.test1(A01_test1.java:10)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)

at org.testng.internal.InvokeMethodRunnable.runOne(InvokeMethodRunnable.java:46)

at org.testng.internal.InvokeMethodRunnable.run(InvokeMethodRunnable.java:37)

at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)

at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)

at java.util.concurrent.FutureTask.run(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

 

===============================================

Default test

Tests run: 2, Failures: 1, Skips: 0

===============================================

 

===============================================

Default suite

Total tests run: 2, Failures: 1, Skips: 0

===============================================

[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@3a9bba: 62 ms

[TestNG] Time taken by org.testng.reporters.EmailableReporter@1ed1b0b: 16 ms

[TestNG] Time taken by org.testng.reporters.XMLReporter@1ae90c: 15 ms

[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@18352d8: 0 ms

[TestNG] Time taken by [TestListenerAdapter] Passed:0 Failed:0 Skipped:0]: 16 ms

 
 
 
 


From: [hidden email] [mailto:[hidden email]] On Behalf Of Krishnan Mahadevan
Sent: Friday, January 27, 2012 2:08 PM
To: [hidden email]
Subject: Re: [testng-users] Question about timeOut parameter inside a a @Test

Am not quite sure if I got this question right, but I ran a quick check and dont see a problem. Perhaps you can elaborate more with a demo class and provide the expected results Vs actual results that you are seeing along with the testng version that you are working with.

As expected only method1 failed for me and method2 passed.
Am working with TestNG eclipse plug-in version 6.3.0


Here's my sample test :
public class TestNGTimeOutDemo {
@Test(timeOut=1500)
public void method1() throws InterruptedException {
Thread.sleep(2000);
}

@Test
public void method2() throws InterruptedException {
Thread.sleep(2000);
Assert.assertTrue(true);
}
}

PASSED: method2

FAILED: method1

org.testng.internal.thread.ThreadTimeoutException: Method org.testng.internal.TestNGMethod.method1() didn't finish within the time-out 1500



Thanks & Regards
Krishnan Mahadevan

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


On Fri, Jan 27, 2012 at 5:29 PM, Tsiakos, Panagiotis <[hidden email]> wrote:

Hi ,

I have a guestion about the timeOut parameter inside a @Test method  (

timeOut The maximum number of milliseconds this test should take.
)

saw that when the timeoout expires the test fails throwing a timeout exception and the main thread goes

to the next @Test (that is what I expected)

The problem is that I observed also that a second threard is spawned in parallel, that tries to execute the @Test with the expired timeout,

from the point that the timeout occurred. That really messes the execution of the @Test methods inside a test class.

Is this a bug or for some reason it works as designed?

Regards

Panagiotis

 

Panagiotis Tsiakos

Siemens Enterprise Communications S.A.

Enterprise Product Development
15 Andrea Metaxa str., Room 1.14

GR 145 64, Nea Kifisia
Athens, Greece
Tel: <A href="tel:%2B30%20210%208189609" target=_blank value="+302108189609">+30 210 8189609

Fax: +30 210 8189761
mailto: [hidden email]

 

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: Question about timeOut parameter inside a a @Test

Cédric Beust ♔-2
In reply to this post by Tsiakos, Panagiotis
Hi Tsiakos,

It's a side effect of the implementation, which spawns a single thread with the given time out just for that method.

I'm aware that it causes issues in a few cases (such as when a transaction context is stored in thread local), but I haven't looked into fixing this yet (it's not trivial).

-- 
Cédric




On Fri, Jan 27, 2012 at 3:59 AM, Tsiakos, Panagiotis <[hidden email]> wrote:

Hi ,

I have a guestion about the timeOut parameter inside a @Test method  (

timeOut The maximum number of milliseconds this test should take.
)

saw that when the timeoout expires the test fails throwing a timeout exception and the main thread goes

to the next @Test (that is what I expected)

The problem is that I observed also that a second threard is spawned in parallel, that tries to execute the @Test with the expired timeout,

from the point that the timeout occurred. That really messes the execution of the @Test methods inside a test class.

Is this a bug or for some reason it works as designed?

Regards

Panagiotis

 

Panagiotis Tsiakos

Siemens Enterprise Communications S.A.

Enterprise Product Development
15 Andrea Metaxa str., Room 1.14

GR 145 64, Nea Kifisia
Athens, Greece
Tel: <a href="tel:%2B30%20210%208189609" value="+302108189609" target="_blank">+30 210 8189609

Fax: +30 210 8189761
mailto: [hidden email]

 

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: Question about timeOut parameter inside a a @Test

gogo mts
Hi Cedric,

The example of this case is not so rare since in most of the cases there are other method calls inside an @Test method. Don't you think you should give it a try or it is pretty complex?

Georgia


2012/1/27 Cédric Beust ♔ <[hidden email]>
Hi Tsiakos,

It's a side effect of the implementation, which spawns a single thread with the given time out just for that method.

I'm aware that it causes issues in a few cases (such as when a transaction context is stored in thread local), but I haven't looked into fixing this yet (it's not trivial).

-- 
Cédric




On Fri, Jan 27, 2012 at 3:59 AM, Tsiakos, Panagiotis <[hidden email]> wrote:

Hi ,

I have a guestion about the timeOut parameter inside a @Test method  (

timeOut The maximum number of milliseconds this test should take.
)

saw that when the timeoout expires the test fails throwing a timeout exception and the main thread goes

to the next @Test (that is what I expected)

The problem is that I observed also that a second threard is spawned in parallel, that tries to execute the @Test with the expired timeout,

from the point that the timeout occurred. That really messes the execution of the @Test methods inside a test class.

Is this a bug or for some reason it works as designed?

Regards

Panagiotis

 

Panagiotis Tsiakos

Siemens Enterprise Communications S.A.

Enterprise Product Development
15 Andrea Metaxa str., Room 1.14

GR 145 64, Nea Kifisia
Athens, Greece
Tel: <a href="tel:%2B30%20210%208189609" value="+302108189609" target="_blank">+30 210 8189609

Fax: +30 210 8189761
mailto: [hidden email]

 

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: Question about timeOut parameter inside a a @Test

dhuang
Hi, 

I am running into the same problem as tsak stated above.  Is there a solution/workaround?  Thank you.

On Wednesday, February 1, 2012 3:13:25 AM UTC-8, gogomts wrote:
Hi Cedric,

The example of this case is not so rare since in most of the cases there are other method calls inside an @Test method. Don't you think you should give it a try or it is pretty complex?

Georgia


2012/1/27 Cédric Beust ♔ <[hidden email]>
Hi Tsiakos,

It's a side effect of the implementation, which spawns a single thread with the given time out just for that method.

I'm aware that it causes issues in a few cases (such as when a transaction context is stored in thread local), but I haven't looked into fixing this yet (it's not trivial).

-- 
Cédric




On Fri, Jan 27, 2012 at 3:59 AM, Tsiakos, Panagiotis <[hidden email]> wrote:

Hi ,

I have a guestion about the timeOut parameter inside a @Test method  (

timeOut The maximum number of milliseconds this test should take.
)

saw that when the timeoout expires the test fails throwing a timeout exception and the main thread goes

to the next @Test (that is what I expected)

The problem is that I observed also that a second threard is spawned in parallel, that tries to execute the @Test with the expired timeout,

from the point that the timeout occurred. That really messes the execution of the @Test methods inside a test class.

Is this a bug or for some reason it works as designed?

Regards

Panagiotis

 

Panagiotis Tsiakos

Siemens Enterprise Communications S.A.

Enterprise Product Development
15 Andrea Metaxa str., Room 1.14

GR 145 64, Nea Kifisia
Athens, Greece
Tel: +30 210 8189609

Fax: +30 210 8189761
mailto: [hidden email]

 

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/0nfneW6S_GsJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: Question about timeOut parameter inside a a @Test

vikas2.j@gmail.com
I am having the same issue, in fact in my other method call are made to the other service, here Testng is skipping the sleep but sending multiple call to other service in same millisecond.

and which creates lot of adverse effect.

Regards
Vikas

On Friday, June 1, 2012 1:45:52 PM UTC-4, dhuang wrote:
Hi, 

I am running into the same problem as tsak stated above.  Is there a solution/workaround?  Thank you.

On Wednesday, February 1, 2012 3:13:25 AM UTC-8, gogomts wrote:
Hi Cedric,

The example of this case is not so rare since in most of the cases there are other method calls inside an @Test method. Don't you think you should give it a try or it is pretty complex?

Georgia


2012/1/27 Cédric Beust ♔ <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="0nfneW6S_GsJ">ced...@...>
Hi Tsiakos,

It's a side effect of the implementation, which spawns a single thread with the given time out just for that method.

I'm aware that it causes issues in a few cases (such as when a transaction context is stored in thread local), but I haven't looked into fixing this yet (it's not trivial).

-- 
Cédric




On Fri, Jan 27, 2012 at 3:59 AM, Tsiakos, Panagiotis <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="0nfneW6S_GsJ">panagioti...@siemens-enterprise.com> wrote:

Hi ,

I have a guestion about the timeOut parameter inside a @Test method  (

timeOut The maximum number of milliseconds this test should take.
)

saw that when the timeoout expires the test fails throwing a timeout exception and the main thread goes

to the next @Test (that is what I expected)

The problem is that I observed also that a second threard is spawned in parallel, that tries to execute the @Test with the expired timeout,

from the point that the timeout occurred. That really messes the execution of the @Test methods inside a test class.

Is this a bug or for some reason it works as designed?

Regards

Panagiotis

 

Panagiotis Tsiakos

Siemens Enterprise Communications S.A.

Enterprise Product Development
15 Andrea Metaxa str., Room 1.14

GR 145 64, Nea Kifisia
Athens, Greece
Tel: +30 210 8189609

Fax: +30 210 8189761
mailto: <a title="blocked::mailto:panagiotis.tsiakos@siemens.com mailto:panagiotis.tsiakos@siemens.com" href="javascript:" target="_blank" gdf-obfuscated-mailto="0nfneW6S_GsJ">panagiotis.tsiakos@siemens-enterprise.com

 

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="0nfneW6S_GsJ">testng...@....
To unsubscribe from this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="0nfneW6S_GsJ">testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="0nfneW6S_GsJ">testng...@....
To unsubscribe from this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="0nfneW6S_GsJ">testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

--
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 http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Question about timeOut parameter inside a a @Test

Venkatesh Malepati
In reply to this post by Tsiakos, Panagiotis
Yes, my team is also facing the same issue. Anybody has a work around. Thank you.

On Friday, January 27, 2012 at 6:59:37 AM UTC-5, tsak wrote:

Hi ,

I have a guestion about the timeOut parameter inside a @Test method  (

timeOut The maximum number of milliseconds this test should take.
)

saw that when the timeoout expires the test fails throwing a timeout exception and the main thread goes

to the next @Test (that is what I expected)

The problem is that I observed also that a second threard is spawned in parallel, that tries to execute the @Test with the expired timeout,

from the point that the timeout occurred. That really messes the execution of the @Test methods inside a test class.

Is this a bug or for some reason it works as designed?

Regards

Panagiotis

 

Panagiotis Tsiakos

Siemens Enterprise Communications S.A.

Enterprise Product Development
15 Andrea Metaxa str., Room 1.14

GR 145 64, Nea Kifisia
Athens, Greece
Tel: +30 210 8189609

Fax: +30 210 8189761
mailto: <a title="blocked::mailto:panagiotis.tsiakos@siemens.com mailto:panagiotis.tsiakos@siemens.com" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;" href="javascript:" target="_blank" rel="nofollow" gdf-obfuscated-mailto="LQxuLct8DWwJ">panagiotis.tsiakos@siemens-enterprise.com

 

--
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 http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.