Skip to content

Allow @ResourceLock and @Isolated to work across processes #4211

@Arthurm1

Description

@Arthurm1

@ResourceLock is great for ensuring tests run with as much concurrency as possible while protecting exclusive access to resources for the duration of a single test method/class.

My issue is that it only protects the resource within that single JUnit test run. If I execute a number of different test runs simultaneously (in different processes) and those test runs have tests that use @ResourceLock("foo") then foo can be accessed at the same time from the different test runs.

This happens for me as I use Gradle and have many subprojects. Gradle allows running subprojects tests in parallel or sequentially. Running tests in parallel means each project will run its tests in its own process and so @ResourceLock("foo") will not be respected across subprojects.

Because of this I have to run each subproject's test task sequentially which is slower.

Deliverables

Ideally there would be an option on @ResourceLock to specify the level of the lock e.g. @ResourceLock(level = LOCAL | MACHINE).

For @ResourceLock("Foo", level = LOCAL), the locking would behave as it currently is and this would be the default.
For @ResourceLock("Foo", level = MACHINE) the lock on Foo would prevent any junit runs on that machine from simultaneously accessing Foo. (Perhaps using java.nio.channels.FileLock)

It would be good if this could be extended to @Isolated(level = LOCAL | MACHINE) to allow only a single test to run concurrently even during multiple simultaneous test runs.

Or is there already a way to do this?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions