Skip to content

Assertions.assertTimeoutPreemptively() breaks Spring test transaction rollback #1701

@oopschen

Description

@oopschen

Overview

We use JUnit Jupiter 5.3.1 in our web project, the assertTimeoutPreemptively() method will break the transaction rollback in spring's testing framework. As we use DataSourceTransactionManager as the main transaction manager, the manager will propagate the transaction in the same thread, not across threads. The assertTimeoutPreemptively() method starts a new thread running our code which differs from the main test thread resulting in transaction propagation breakage.

Steps to reproduce

  1. run test code surround by assertTimeoutPreemptively()
  2. the test code request a URI in Spring's mocked web environment
  3. the URI insert a record to database
  4. the record is not rolled back

Context

  • 5.3.1 (Jupiter/Vintage/Platform):
  • Intellij

Possible resolution

Run test code in main test thread and run timeout in spawned thread.

Related Issues

Deliverables

  • Add note regarding the use of assertTimeoutPreemptively() and the effects on ThreadLocal storage (in general) and with Spring's transaction management (as an example) in ...
    • Javadoc
    • User Guide

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions