Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow declaring exclusive resources for child nodes #4151

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

vdmitrienko
Copy link
Contributor

@vdmitrienko vdmitrienko commented Nov 23, 2024

Issue: #3102

Overview

Allow declaring "shared resources" for direct child nodes via the new @ResourceLock(target = CHILDREN) attribute.

Using the @ResourceLock(target = CHILDREN) in a class-level annotation has the same semantics as adding an annotation with the same value and mode to each test method and nested test class declared in this class.

This may improve parallelization when a test class declares a READ lock, but only a few methods hold a READ_WRITE lock.


I hereby agree to the terms of the JUnit Contributor License Agreement.


Definition of Done

Copy link
Member

@marcphilipp marcphilipp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I only found some minor things.

* <li>a test class
* - test methods and nested test classes declared in the class.</li>
* <li>a nested test class
* - test methods declared in the nested class.</li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* - test methods declared in the nested class.</li>
* - test methods and nested test classes declared in the nested class.</li>

* - test methods and nested test classes declared in the class.</li>
* <li>a nested test class
* - test methods declared in the nested class.</li>
* <li>a test method - considered to have no children.</li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails, right? We should document that CHILDREN cannot be used on methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right. Added


Using the `target = CHILDREN` in a class-level `{ResourceLock}` annotation
has the same semantics as adding an annotation with the same `value` and `mode`
to each test method declared in this class.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
to each test method declared in this class.
to each test method and nested test class declared in this class.

has the same semantics as adding an annotation with the same `value` and `mode`
to each test method declared in this class.

It may improve parallelization when a test class declares a `READ` lock,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
It may improve parallelization when a test class declares a `READ` lock,
This may improve parallelization when a test class declares a `READ` lock,

but only a few methods hold a `READ_WRITE` lock.

Tests in the following example would run in the `SAME_THREAD` if the `{ResourceLock}`
doesn't have the `target = CHILDREN`. This is because the test class declares a `READ`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
doesn't have the `target = CHILDREN`. This is because the test class declares a `READ`
didn't have `target = CHILDREN`. This is because the test class declares a `READ`

Tests in the following example would run in the `SAME_THREAD` if the `{ResourceLock}`
doesn't have the `target = CHILDREN`. This is because the test class declares a `READ`
shared resource, but one test method holds a `READ_WRITE` lock,
which forces the `SAME_THREAD` execution mode for all the test methods.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
which forces the `SAME_THREAD` execution mode for all the test methods.
which would force the `SAME_THREAD` execution mode for all the test methods.

@vdmitrienko
Copy link
Contributor Author

Looks good! I only found some minor things.

@marcphilipp thanks for the review 🙂

Updated according to the comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a way to inherit ResourceLocks that allows for more parallel execution of tests
2 participants