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

Opt-in support for parallel execution #60

Closed
marcphilipp opened this issue Dec 11, 2015 · 45 comments
Closed

Opt-in support for parallel execution #60

marcphilipp opened this issue Dec 11, 2015 · 45 comments

Comments

@marcphilipp
Copy link
Member

Related to #90.

@marcphilipp marcphilipp self-assigned this Dec 11, 2015
@marcphilipp marcphilipp added this to the Alpha 1 milestone Dec 11, 2015
@marcphilipp marcphilipp modified the milestones: M1, Alpha 1 Jan 11, 2016
@marcphilipp marcphilipp modified the milestones: 5.0 Backlog, 5.0 M1 Apr 15, 2016
@ptahchiev
Copy link

+1 for this one. TestNG has had this feature for a long time and the maven surefire plugin supports parallel tests out of the box:

http://maven.apache.org/surefire/maven-surefire-plugin/examples/fork-options-and-parallel-execution.html

@radai-rosenblatt
Copy link

+1. would definitely help in shortening build times

@leonard84
Copy link
Collaborator

Will this be part of the platform, or the engine, or both?

While thinking about better support for parallel execution in Spock, I identified some problems that should be handled by the testing framework.

  • Parallel (integration) testing in conjunction with global state (system properties/db/...) can leak into other tests
    • e.g., Spock has the @RestoreSystemProperties extension, which will save the SystemProperties before the execution and restore it after the test. This works fine for single threaded execution, but in concurrent test execution this will lead to race conditions.
    • The bad solution would be to disable concurrent execution

My idea is that each test (class/method) could declare its use of global resources, e.g. @UseResource(value="SystemProperties", mode=ReadWrite). The engine would keep a list of ReentrantReadWriteLock for each of the resources and acquire/release those locks accordingly. Care would have to be taken to avoid deadlocks, by ordering the lock acquisition accordingly.

This way the framework could offer the maximum concurrency while still offering providing tools to isolate problematic tests.

There would be a list of predefined resources, such as Global (all tests would implicitly acquire a ReadLock for this) or SystemProperties, but users can define their own to match their application.

Thoughts? Of course all names are open for change.

@marcphilipp
Copy link
Member Author

I think an engine needs to decide on which level tests can be executed in parallel. However, there are quite a few similarities between different testing frameworks where the platform could provide support, e.g. via a base implementation that multiple test engines can use.

I really like your reentrant lock idea! Is there already a TestEngine implementation for Spock? If so, do you use the HierarchicalTestEngine abstraction? I wrote a ForkJoinPool based prototype for it some time ago.

@leonard84
Copy link
Collaborator

@marcphilipp no Spock doesn't have it's own TestEngine yet. As better support for parallelism would be a major part in it, I'd wanted to check in on this first before running in the wrong direction/doing redundant work. Switching to a own TestEngine will be done with Spock 2.0

@wlsc
Copy link

wlsc commented Oct 27, 2017

Any news on that topic?

@sormuras
Copy link
Member

sormuras commented Mar 7, 2018

[...] And is it possible execute it with maven-surefire-plugin?

See the Maven instructions shown at jitpack URL above. If it works with Surefire? No idea. Keen on trying it out?

@sormuras
Copy link
Member

sormuras commented Mar 7, 2018

@marcphilipp The https://github.com/junit-team/junit5/tree/experiments/parallel-execution branch is still based on 5.1-M2 ... it lacks the final org.junit.jupiter.api.condition package and other fixes. Will @leonard84 or you rebase it to master in the near future?

@marcphilipp
Copy link
Member Author

I'll meet with @leonard84 this weekend. I'll try to merge master into the feature branch before.

@marcphilipp
Copy link
Member Author

I've just updated the feature branch. Feel free to try it out using Jitpack.

@dlanaghen
Copy link

Parallel testing is a big deal to us. I have experimented with your version and my first simple tests look real promising. Is there a ball park for when this might get merged into Junit5 and when an official release timeframe might be? If this is going to be real, I might forge ahead and begin really exercising it.

@marcphilipp
Copy link
Member Author

@dlanaghen Thanks for experimenting with it and letting us know!

We plan to include it as an experimental feature in 5.3 M1 which is currently scheduled for June 24. If no regressions or major issues are found, you can expect a RC and the GA release within two weeks from that date.

@dlanaghen
Copy link

@marcphilipp this is great news. With better parameterized testing features and your new multi-threaded test runner, you will have filled a couple of big holes in JUnit. Thanks for your work.

@koretzki
Copy link

koretzki commented Jun 3, 2018

@marcphilipp, great to hear, this (no parallelism) was a road blocker for us to adopt fully JUnit 5.

@ghost ghost removed the status: in progress label Jun 22, 2018
marcphilipp added a commit that referenced this issue Jun 22, 2018
This commit adds opt-in support for parallel test execution and
capturing output to `System.out` and `System.err`. Both features are
disabled by default but can be enabled and configured using
configuration parameters.

The implementation is based on the Fork/Join Framework and designed to
be reusable by other test engines that extend HierarchicalTestEngine.

The Jupiter API provides annotations to declare which shared resources a
test needs to access and in which way. Moreover, the execution mode of a
test can be influenced.

In addition, a number of TestExecutionListeners have been made
thread-safe.

The documentation subproject is now configured to execute tests in
parallel. All other subprojects will have to wait as Gradle currently
blows up when used with parallel test execution.

Resolves #60. Closes #1461.

Co-authored-by: Leonard Brünings <lord_damokles@gmx.net>
Co-authored-by: Christian Stein <sormuras@gmail.com>
Andrei94 pushed a commit to Andrei94/junit5 that referenced this issue Jun 23, 2018
This commit adds opt-in support for parallel test execution and
capturing output to `System.out` and `System.err`. Both features are
disabled by default but can be enabled and configured using
configuration parameters.

The implementation is based on the Fork/Join Framework and designed to
be reusable by other test engines that extend HierarchicalTestEngine.

The Jupiter API provides annotations to declare which shared resources a
test needs to access and in which way. Moreover, the execution mode of a
test can be influenced.

In addition, a number of TestExecutionListeners have been made
thread-safe.

The documentation subproject is now configured to execute tests in
parallel. All other subprojects will have to wait as Gradle currently
blows up when used with parallel test execution.

Resolves junit-team#60. Closes junit-team#1461.

Co-authored-by: Leonard Brünings <lord_damokles@gmx.net>
Co-authored-by: Christian Stein <sormuras@gmail.com>
@markthegrea
Copy link

Where is the documentation on how to use this?

@sormuras
Copy link
Member

@markthegrea It is still on the snapshot version of the User-Guide, because it is integrated in version 5.3-RC1 of the Jupiter Engine: https://junit.org/junit5/docs/snapshot/user-guide/#writing-tests-parallel-execution

When 5.3 is released, the current User-Guide will show it, too.

dotCipher pushed a commit to dotCipher/junit5 that referenced this issue Sep 18, 2018
This commit adds opt-in support for parallel test execution and
capturing output to `System.out` and `System.err`. Both features are
disabled by default but can be enabled and configured using
configuration parameters.

The implementation is based on the Fork/Join Framework and designed to
be reusable by other test engines that extend HierarchicalTestEngine.

The Jupiter API provides annotations to declare which shared resources a
test needs to access and in which way. Moreover, the execution mode of a
test can be influenced.

In addition, a number of TestExecutionListeners have been made
thread-safe.

The documentation subproject is now configured to execute tests in
parallel. All other subprojects will have to wait as Gradle currently
blows up when used with parallel test execution.

Resolves junit-team#60. Closes junit-team#1461.

Co-authored-by: Leonard Brünings <lord_damokles@gmx.net>
Co-authored-by: Christian Stein <sormuras@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests