Skip to content

DirtiesContextTestExecutionListener has unexpected execution order leading to errors #34225

Closed as not planned
@tfactor2

Description

We encountered an issue where our custom test execution listener, responsible for cleaning the database after-test, was executed after the ApplicationContext was cleaned up. We had set the listener order to 3000 to prevent conflicts with other internal listeners.

However, we didn't know that DirtiesContextTestExecutionListener had the same order level (3000), leading our cleanup listener to run after the context was marked dirty.
This behavior led to unexpected results - Spring initiated a new context since the previous one was removed, resulting in the database being cleaned for another test.

Additionally, it would be great to understand the rationale behind 3000 for DirtiesContextTestExecutionListener.
Looks like the logic should be more complex:
after the method marking should be executed last (having listener with the lowest order value),
before the method marking should be executed first (listener with the highest order value).

Spring Version: 6.1.13

Metadata

Assignees

No one assigned

    Labels

    in: testIssues in the test modulestatus: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions