Skip to content

Conversation

@raccoonback
Copy link
Contributor

Fixes #5155

This PR enables the use of @ResourceLock on classes annotated with @ClassTemplate.

Background

Currently, applying @ResourceLock to a @ClassTemplate class results in the following failure:

Dynamic test descriptors must not declare exclusive resources

This happens because ClassTemplateInvocationTestDescriptor#getExclusiveResources() returns a non-empty set, causing the invocation descriptor to report exclusive resources even though the enclosing ClassTemplateTestDescriptor already collects and exposes them at the class level.

Summary of Changes

  • Override ClassTemplateInvocationTestDescriptor#getExclusiveResources() to always return an empty set.

    • Class-level exclusive resources are already managed by ClassTemplateTestDescriptor, so the invocation descriptor should not contribute additional exclusive resources.
  • Add a dedicated test classTemplateWithResourceLockExecutesSuccessfully() to verify that:

    • A @ClassTemplate class annotated with @ResourceLock executes successfully.
    • Both test and container events complete without errors.

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


Definition of Done

@raccoonback
Copy link
Contributor Author

@marcphilipp
Hello.
I'd appreciate it if you could review this PR.

@mpkorstanje mpkorstanje modified the milestones: 6.0.2, 6.1.0-M2 Nov 28, 2025

@Test
void classTemplateWithResourceLockExecutesSuccessfully() {
var results = executeTestsForClass(ClassTemplateWithResourceLockTestCase.class);
Copy link
Member

Choose a reason for hiding this comment

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

I think we should also verify that the discovered TestDescriptor.getExclusiveResources() return the expected Set<ExclusiveResource> for the class template.

You can do that by calling discoverTestsForClass(ClassTemplateWithResourceLockTestCase.class) and calling getEnginesDescriptor() which will have a single child: the class template descriptor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@marcphilipp
As suggested, I’ve added the classTemplateWithResourceLockCollectsExclusiveResources test.

@raccoonback raccoonback force-pushed the 5155-fix-exclusive-resources-for-class-template branch from 659c7ea to ea7cfc8 Compare December 1, 2025 03:18
@raccoonback
Copy link
Contributor Author

@marcphilipp
Hello.
I’ve applied the review feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Class templates should be able to declare @ResourceLock

3 participants