Skip to content

Parallelization control of DynamicNode #2497

@big-andy-coates

Description

@big-andy-coates

@TestFactory can return a stream of DynamicContainers and DynamicTest. It would be awesome if we could run containers in parallel, but the tests within containers on the same thread.

The @Execution seems to only allow you to switch from everything parallel/concurrent or everything on the same thread.

The configuration parameters junit.jupiter.execution.parallel.mode.default and junit.jupiter.execution.parallel.mode.classes.default also don't seem to allow such a configuration, probably because all test suites and test are coming from the same class.

For example: the following should allow tests test1 and test2 that are in suite1 to be run on the same thread, and the tests in suite2 to be run on a different, but consistent thread:

static class Runner {

    @TestFactory
    Stream<DynamicNode> systemTest() {
        final Stream<DynamicNode> tests1 = Stream.of(
                        DynamicTest.dynamicTest("test1", () -> {System.out.println(Thread.currentThread().getId() + " -test1");}),
                        DynamicTest.dynamicTest("test2", () -> {System.out.println(Thread.currentThread().getId() + " - test2");}));

        final Stream<DynamicNode> tests2 = Stream.of(
                        DynamicTest.dynamicTest("test3", () -> {System.out.println(Thread.currentThread().getId() + " -test3");}),
                        DynamicTest.dynamicTest("test4", () -> {System.out.println(Thread.currentThread().getId() + " - test4");}));

        return Stream.of(
                DynamicContainer.dynamicContainer("suite1", tests1),
                DynamicContainer.dynamicContainer("suite2", tests2));
    }
}

Maybe this could be achieved via one or more of:

  • a new junit.jupiter.execution.parallel.mode.container.default property
  • a field on @TestFactory to control execution
  • an enhancement to @Execution
  • a parameter to DynamicContainer

Thanks!

Activity

marcphilipp

marcphilipp commented on Dec 22, 2020

@marcphilipp
Member

Tentatively slated for 5.8 M1 solely for the purpose of team discussion.

added this to the 5.8 M1 milestone on Dec 22, 2020
sic-poths

sic-poths commented on Jan 25, 2021

@sic-poths

We have a similar case, but would like to run the first level of dynamic nodes in sequence, but tests under each level can be run in parallel. It would be great to be able to define the ExecutionMode on each DynamicContainer instance.

modified the milestones: 5.8 M1, 5.8 M2/RC1 on Feb 7, 2021
removed this from the 5.8 RC1 milestone on Aug 15, 2021
stale

stale commented on Sep 16, 2022

@stale

This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. Thank you for your contribution.

sic-poths

sic-poths commented on Sep 16, 2022

@sic-poths

I would still be really interested in a solution to this problem. Are there any thoughts from the team on what a good implementation of a more fine granular "execution-order-control" for dynamic tests could be? Maybe I would give it a try to create a PR, but I only know the codebase as a user.

niteshhardikar

niteshhardikar commented on Jan 31, 2023

@niteshhardikar

Perfectly explained by @big-andy-coates. I have run into the same requirement where I want to run my DynamicContainers in parallel but the DynamicTests within each container sequentially. Is this slated for any upcoming release or is there any other solution to this problem for instance using the Extension model? Any inputs are highly appreciated.

marcphilipp

marcphilipp commented on Apr 22, 2023

@marcphilipp
Member

I wonder if a configuration parameter would really be adequate here. Wouldn't it be better if DynamicNode would provide an API to configure the execution mode similiar to @Execution for regular test classes and methods?

@big-andy-coates @sic-poths @niteshhardikar WDYT?

25 remaining items

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @novoj@marcphilipp@sonthanh@big-andy-coates@Janrupf

      Issue actions

        Parallelization control of DynamicNode · Issue #2497 · junit-team/junit-framework