timeout attribute on @Test causes JPA transactions not to work properly

View: New views
10 Messages — Rating Filter:   Alert me  

timeout attribute on @Test causes JPA transactions not to work properly

by Zaphod-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



I've spent the past 2 weeks trying to figure out why the transactions
in our JPA tests no longer work correctly, the problem has been that
too many things have changed at once - migrated from JUnit3 to TestNG,
from Spring 2.5.6 to 3.0.0.M4, changed all the test to Spring
TestContext framework style, and in the background other developers
have made some strategic changes to the way we use JPA !

To add additional confusion, this problem doesn't manifest itself when
running the tests inside Eclipse ("developer mode") but only when
running them from Ant ("continuous build mode") so it has left
everyone else in the project with a bit of a loss of confidence in
myself as they no longer trust the continuous build results :-(

However I've now narrowed it down to a fairly straightforward sample
project which clearly demonstrates the problem.
If the tests are run with a timeout attribute, they fail at
EntityManager.flush() because there is no transaction.
If the timeout is set to zero, they pass.
(they run quickly, there's no question that the timeout is too short,
the problem is just an artefact of a timeout being set).

I'm setting the timeout using an IAnnotationTransformer which sets a
default value on all tests that don't already have an explicit timeout
setting.  We had to use @Test(timeout) rather than the overall timeOut
setting in the Ant task, because the latter simply  terminates the
process abruptly causing a loss of data (test results and coverage)
when it fires.

I just found that you already have a JIRA issue for this -
http://jira.opensymphony.com/browse/TESTNG-280
I can attach my sample project if necessary.

We're using Toplink Essentials from Glassfish 2.1 with Spring 3.0.0.M4
(to get class-level @DirtiesContext) and TestNG 5.10.

Unfortunately this is a complete show-stopper for us.  But I really
don't want to be forced back to the dark side, there are so many
benefits to using TestNG.  If it's not possible to get a fix out
quickly, I'd appreciate some pointers as to where to look in order to
create my own patch.

Thanks

Ed



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


Re: timeout attribute on @Test causes JPA transactions not to work properly

by Cédric Beust ♔ :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Ed,

Sorry to hear about your problems.

This class is part of the Spring distribution (it was written by Rod and Juergen), so I'm afraid I can't be of much help here.  Maybe someone more versed in Spring and TestNG can help you out here, or maybe you could ask this question on the Spring forums?

--
Cedric


On Thu, Sep 17, 2009 at 8:58 AM, Zaphod <ed.j.randall@...> wrote:


I've spent the past 2 weeks trying to figure out why the transactions
in our JPA tests no longer work correctly, the problem has been that
too many things have changed at once - migrated from JUnit3 to TestNG,
from Spring 2.5.6 to 3.0.0.M4, changed all the test to Spring
TestContext framework style, and in the background other developers
have made some strategic changes to the way we use JPA !

To add additional confusion, this problem doesn't manifest itself when
running the tests inside Eclipse ("developer mode") but only when
running them from Ant ("continuous build mode") so it has left
everyone else in the project with a bit of a loss of confidence in
myself as they no longer trust the continuous build results :-(

However I've now narrowed it down to a fairly straightforward sample
project which clearly demonstrates the problem.
If the tests are run with a timeout attribute, they fail at
EntityManager.flush() because there is no transaction.
If the timeout is set to zero, they pass.
(they run quickly, there's no question that the timeout is too short,
the problem is just an artefact of a timeout being set).

I'm setting the timeout using an IAnnotationTransformer which sets a
default value on all tests that don't already have an explicit timeout
setting.  We had to use @Test(timeout) rather than the overall timeOut
setting in the Ant task, because the latter simply  terminates the
process abruptly causing a loss of data (test results and coverage)
when it fires.

I just found that you already have a JIRA issue for this -
http://jira.opensymphony.com/browse/TESTNG-280
I can attach my sample project if necessary.

We're using Toplink Essentials from Glassfish 2.1 with Spring 3.0.0.M4
(to get class-level @DirtiesContext) and TestNG 5.10.

Unfortunately this is a complete show-stopper for us.  But I really
don't want to be forced back to the dark side, there are so many
benefits to using TestNG.  If it's not possible to get a fix out
quickly, I'd appreciate some pointers as to where to look in order to
create my own patch.

Thanks

Ed







--
Cédric



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


Re: timeout attribute on @Test causes JPA transactions not to work properly

by Zaphod-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I've posted in detail over on the Spring Data Access forum.

http://forum.springsource.org/showthread.php?p=260665

Hopefully they will have a fix and not say "It's a TestNG problem" ;-)

Regards

Ed

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


Re: timeout attribute on @Test causes JPA transactions not to work properly

by Cédric Beust ♔ :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Thu, Sep 17, 2009 at 10:49 AM, Zaphod <ed.j.randall@...> wrote:

I've posted in detail over on the Spring Data Access forum.

http://forum.springsource.org/showthread.php?p=260665

Hopefully they will have a fix and not say "It's a TestNG problem" ;-)

That's always a possibility but I'd like them to do the preliminary investigation :-)

--
Cédric



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


Re: timeout attribute on @Test causes JPA transactions not to work properly

by krishnan.1000 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


You might also want to file a JIRA with Spring issue tracker
http://jira.springframework.org/secure/IssueNavigator.jspa?reset=true&mode=hide&pid=10000&sorter/order=DESC&sorter/field=priority&resolution=-1&component=10645

It is possible that your query may not get answered on the forum.

Thanks,

Karthik

On Sep 17, 11:40 am, Cédric Beust ♔ <cbe...@...> wrote:

> On Thu, Sep 17, 2009 at 10:49 AM, Zaphod <ed.j.rand...@...> wrote:
>
> > I've posted in detail over on the Spring Data Access forum.
>
> >http://forum.springsource.org/showthread.php?p=260665
>
> > Hopefully they will have a fix and not say "It's a TestNG problem" ;-)
>
> That's always a possibility but I'd like them to do the preliminary
> investigation :-)
>
> --
> ***Cédric
> *
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng-users@...
To unsubscribe from this group, send email to testng-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: timeout attribute on @Test causes JPA transactions not to work properly

by Zaphod-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Yes, I noticed the Spring forums are quite quiet since they started
charging big $$$ for support ;-)

http://jira.springframework.org/browse/SPR-6124


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


Re: timeout attribute on @Test causes JPA transactions not to work properly

by Mike Hancock-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Have you tried the Java Ranch?  They have a lot forums and have been
helpful to me in the past.
http://www.coderanch.com/forums/

On Sep 18, 4:04 pm, Zaphod <ed.j.rand...@...> wrote:
> Yes, I noticed the Spring forums are quite quiet since they started
> charging big $$$ for support ;-)
>
> http://jira.springframework.org/browse/SPR-6124
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng-users@...
To unsubscribe from this group, send email to testng-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: timeout attribute on @Test causes JPA transactions not to work properly

by Zaphod-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


No problem, Spring have updated the JIRA issue confirming that it is a
bug, scheduled for fix in 3.0RC1 at present.

Thanks

Ed

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


Re: timeout attribute on @Test causes JPA transactions not to work properly

by Zaphod-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message




Spring have just updated my bug about TestNG timeouts in their
TestContext framework :-

https://jira.springsource.org/browse/SPR-6124

"I was able to verify your claim. The cause is that the
{{invokeWithTimeout(...)}} method
in TestNG's {{MethodHelper}} class spawns a new thread to execute a
timed test. Spring's
transaction support, however, registers the current transaction
resources, etc. in a
{{ThreadLocal}} which is bound to the thread of the test runner. Thus,
the timed test
method cannot _see_ Spring's transaction.

I'm not sure how easy it will be to solve this issue, since
{{MethodHelper}} is deep in
the internals of TestNG; however, we will look into finding a workable
solution."

Judging from this comment I suspect they might need a bit of help from
you on the TestNG side of the fence, Cedric.

Regards

Ed


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


Re: timeout attribute on @Test causes JPA transactions not to work properly

by Cédric Beust ♔ :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Noted, I'll wait to hear back from them and I'll be happy to integrate any patch they might have to fix this bug.

--
Cédric



On Mon, Oct 26, 2009 at 6:58 AM, Zaphod <ed.j.randall@...> wrote:



Spring have just updated my bug about TestNG timeouts in their
TestContext framework :-

https://jira.springsource.org/browse/SPR-6124

"I was able to verify your claim. The cause is that the
{{invokeWithTimeout(...)}} method
in TestNG's {{MethodHelper}} class spawns a new thread to execute a
timed test. Spring's
transaction support, however, registers the current transaction
resources, etc. in a
{{ThreadLocal}} which is bound to the thread of the test runner. Thus,
the timed test
method cannot _see_ Spring's transaction.

I'm not sure how easy it will be to solve this issue, since
{{MethodHelper}} is deep in
the internals of TestNG; however, we will look into finding a workable
solution."

Judging from this comment I suspect they might need a bit of help from
you on the TestNG side of the fence, Cedric.

Regards

Ed






--
Cédric



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