@@ -3618,6 +3618,29 @@ caution if Spring-managed or application-managed transactions are configured wit
3618
3618
propagation type other than `REQUIRED` or `SUPPORTS` (see the discussion on
3619
3619
<<data-access.adoc#tx-propagation,transaction propagation>> for details).
3620
3620
3621
+ .Preemptive timeouts and test-managed transactions
3622
+ [WARNING]
3623
+ ====
3624
+ Caution must be taken when using any form of preemptive timeouts from a testing framework
3625
+ in conjunction with Spring's test-managed transactions.
3626
+
3627
+ Specifically, Spring’s testing support binds transaction state to the current thread (via
3628
+ a `java.lang.ThreadLocal` variable) _before_ the current test method is invoked. If a
3629
+ testing framework invokes the current test method in a new thread in order to support a
3630
+ preemptive timeout, any actions performed within the current test method will _not_ be
3631
+ invoked within the test-managed transaction. Consequently, the result of any such actions
3632
+ will not be rolled back with the test-managed transaction. On the contrary, such actions
3633
+ will be committed to the persistent store -- for example, a relational database -- even
3634
+ though the test-managed transaction is properly rolled back by Spring.
3635
+
3636
+ Situations in which this can occur include but are not limited to the following.
3637
+
3638
+ * JUnit 4's `@Test(timeout = ...)` support and `TimeOut` rule
3639
+ * JUnit Jupiter's `assertTimeoutPreemptively(...)` methods in the
3640
+ `org.junit.jupiter.api.Assertions` class
3641
+ * TestNG's `@Test(timeOut = ...)` support
3642
+ ====
3643
+
3621
3644
[[testcontext-tx-enabling-transactions]]
3622
3645
===== Enabling and Disabling Transactions
3623
3646
0 commit comments