Skip to content

AbstractTransactionAspect shared between test contexts causes wrong (cached) TransactionManager to be used #34024

@andreiamariei

Description

@andreiamariei

Running two tests with different application contexts will cause the same aspectj AbstractTransactionAspect instance to be reused, (but setBeanFactory is called also for the second test context).

Beceause TransactionAspectSupport.transactionManagerCache is not cleared for the second test context, the transactionManager from first test is used, which can lead to issues.

Created example application where first test closes the db connection, causing failure in second test (if run afterwards in same jvm).

I'm not sure what correct solution can be:

  • clearing transactionManagerCache on TransactionAspectSupport.setBeanFactory can help, but would this be safe when running tests in parallel? if first test context is later reused, would setBeanFactory be called again?
  • I think the real issue is that same AbstractTransactionAspect instance is reused between test contexts, and we should have separate instances
    spring-aspects-issue-cachedtm.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)in: testIssues in the test modulestatus: duplicateA duplicate of another issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions