You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Spring TestContext Framework (TCF) has never supported timed, transactional tests in conjunction with TestNG.
The reason for this is that the transaction managed by the TCF is only active for the currently executing thread; this behavior is in line with standard transaction semantics for Spring. Thus, since TestNG executes the timed test method in a new thread, the test code does not participate in the transaction managed by Spring.
Original Author's Description
If TestNG tests (which extend AbstractTransactionalTestNGSpringContextTests) are run with the timeOut attribute specified in the @Test annotation, they fail at EntityManager.flush() because there is no transaction.
If the timeout is set to zero, they pass.
Analysis
The invokeWithTimeout() method in TestNG's MethodInvocationHelper 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.
Note that MethodInvocationHelper is deep in the internals of TestNG. Thus, it might be difficult to resolve this issue.
Deliverables
Determine if it is possible to integrate the TCF in TestNG so that Spring TestExecutionListeners (specifically TransactionalTestExecutionListener) are executed in the same thread as the timed test.
Ed Randall opened SPR-6124 and commented
Status Quo
The Spring TestContext Framework (TCF) has never supported timed, transactional tests in conjunction with TestNG.
The reason for this is that the transaction managed by the TCF is only active for the currently executing thread; this behavior is in line with standard transaction semantics for Spring. Thus, since TestNG executes the timed test method in a new thread, the test code does not participate in the transaction managed by Spring.
Original Author's Description
If TestNG tests (which extend
AbstractTransactionalTestNGSpringContextTests) are run with thetimeOutattribute specified in the@Testannotation, they fail atEntityManager.flush()because there is no transaction.If the timeout is set to zero, they pass.
Analysis
The
invokeWithTimeout()method in TestNG'sMethodInvocationHelperclass spawns a new thread to execute a timed test. Spring's transaction support, however, registers the current transaction resources, etc. in aThreadLocalwhich is bound to the thread of the test runner. Thus, the timed test method cannot see Spring's transaction.Note that
MethodInvocationHelperis deep in the internals of TestNG. Thus, it might be difficult to resolve this issue.Deliverables
TestExecutionListeners(specificallyTransactionalTestExecutionListener) are executed in the same thread as the timed test.Further Resources
Affects: 2.5.6, 3.0.5, 3.1.2
Attachments:
Issue Links:
Referenced from: commits 1b92a2f
3 votes, 6 watchers