Skip to content

Applying @ResourceLock to a single method in a class template completely turns off parallel execution for this class template #5033

@t-o-n-y-p

Description

@t-o-n-y-p

Steps to reproduce

  1. Set up parallel test execution, for example, with 4 fixed threads
  2. Write a test class with multiple test methods, apply @ResourceLock annotation to one of the methods
  3. Declare this class a template and make a couple of invocations for it
  4. Run the test class. Code example is provided below
junit.jupiter.execution.parallel.enabled=true
junit.jupiter.execution.parallel.mode.default=concurrent
junit.jupiter.execution.parallel.config.strategy=fixed
junit.jupiter.execution.parallel.config.fixed.parallelism=4
@ClassTemplate
@ExtendWith(MethodResourceLockClassTemplateExtension.class)
public class MethodResourceLockClassTemplateTest {

  @Test
  void test1() throws InterruptedException {
    Thread.sleep(2000);
  }

  @Test
  void test2() throws InterruptedException {
    Thread.sleep(2000);
  }

  @Test
  @ResourceLock("1")
  void test3() throws InterruptedException {
    Thread.sleep(2000);
  }
}
@NullMarked
public class MethodResourceLockClassTemplateExtension implements ClassTemplateInvocationContextProvider {

  @Override
  public boolean supportsClassTemplate(ExtensionContext context) {
    return true;
  }

  @Override
  public Stream<? extends ClassTemplateInvocationContext> provideClassTemplateInvocationContexts(ExtensionContext context) {
    return Stream.of(new ClassTemplateInvocationContext() {}, new ClassTemplateInvocationContext() {});
  }
}

Expected result

All tests are being run in parallel, the annotated test method respects the resource lock

Actual result

All tests are being run sequentially

Context

  • Used versions (Jupiter/Vintage/Platform): 6.0.0
  • Build Tool/IDE: IntelliJ IDEA 2025.2.2

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions