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

Configure tests to run concurrently #1913

Closed
wants to merge 2 commits into from
Closed

Conversation

pkoenig10
Copy link
Member

Before this PR

Tests are run sequentially be default.

After this PR

Tests are run concurrently by default.

It appears that the intention in #666 was to run tests concurrently by default. However, that PR was not sufficient - you must also set junit.jupiter.execution.parallel.mode.default.

https://junit.org/junit5/docs/snapshot/user-guide/#writing-tests-parallel-execution

@changelog-app
Copy link

changelog-app bot commented Sep 10, 2021

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

When using the baseline-testing plugin, tests now run concurrently by default.

Check the box to generate changelog(s)

  • Generate changelog entry

@policy-bot policy-bot bot requested a review from fawind September 10, 2021 22:44
@@ -138,9 +138,7 @@ private static void enableJunit5ForTestTask(Test task) {

// https://junit.org/junit5/docs/snapshot/user-guide/#writing-tests-parallel-execution
task.systemProperty("junit.jupiter.execution.parallel.enabled", "true");

// Computes the desired parallelism based on the number of available processors/cores
task.systemProperty("junit.jupiter.execution.parallel.config.strategy", "dynamic");
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the default value so there's no need to configure it explicitly.

https://junit.org/junit5/docs/snapshot/user-guide/#writing-tests-parallel-execution-config

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure we want to run junit5 tests in parallel by default, of the subset that we've manually opted into, I've had to revert several because they were not threadsafe. I would bet that flake rates would jump substantially, though I'd be happy to be proven wrong!

Copy link
Member Author

@pkoenig10 pkoenig10 Sep 10, 2021

Choose a reason for hiding this comment

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

I would bet that flake rates would jump substantially, though I'd be happy to be proven wrong!

I don't disagree, but that probably is an indication that your tests are poorly written. Seems valuable to surface that. It's also fairly easy to make a temporary fix - just add @Execution(SAME_THREAD).

What about running tests classes in parallel but individual methods sequentially?

junit.jupiter.execution.parallel.mode.default = same_thread
junit.jupiter.execution.parallel.mode.classes.default = concurrent

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't disagree, but that probably is an indication that your tests are poorly written. Seems valuable to surface that.

I wouldn't be comfortable making such a blanket statement, but I agree that in the general case it's accurate. Working under the assumption that well-written tests all pass when run in parallel, the flake rate of those which are poorly designed spans a broad range. When they fail it isn't obvious why, or that it's related to concurrency (especially when mockito is involved), so I'm not sure how we'd surface precisely what needs to change.

Perhaps we could start with some experimentation without rolling this out everywhere by default?

Copy link
Member Author

@pkoenig10 pkoenig10 Sep 11, 2021

Choose a reason for hiding this comment

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

I experimented with our large internal authentication repo.

Everything in parallel:

https://c.p.b/workflow-run/29d6a91c-b52b-429b-9b55-fd62224faa8e

  • No unit tests failures.
  • Quite a few integration tests failures. Mostly because we modify the config of the in-process server. This is expected and easy to fix - I wouldn't expect many repos to have this problem since few have integration tests with an in-process server.
  • Small number of ETE test failures. At a glance, most of these appear to be related to our selenium tests and our more custom ETE test setup.

Just classes in parallel:

https://c.p.b/workflow-run/6e675a44-aaaf-40d0-9675-4aacd801dded

  • No unit tests failures.
  • 1 integration test failure. Something fairly specific to our setup.
  • 1 ETE test failure. Also likely related to our custom setup.

Copy link
Member Author

Choose a reason for hiding this comment

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

I also experimented with out large internal filesystem repo, which has a more standard test setup, and got no test failures.

https://c.p.b/workflow-run/e1ccbab0-0042-41dc-893a-4d7e54197ed5

Copy link
Member Author

@pkoenig10 pkoenig10 Sep 12, 2021

Choose a reason for hiding this comment

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

In both cases, the unit test speedups were fairly minimal - since our unit tests are fairly quick to begin with.

But we saw considerable speedup in ETE tests, which are typically one of the slowest steps in our CI builds.

Copy link
Contributor

Choose a reason for hiding this comment

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

Chiming in that we intentionally did not make tests run in parallel by default as people's repos have tests which in general do not allow this, as they depend on state shared between tests, and our big fear was that people's tests would start flaking and they would not know why (as concurrency issues are hard to debug). People can opt in manually per test using @Execution(ExecutionMode.CONCURRENT) which also makes it obvious the tests are running in parallel.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a fair point. The gains here are fairly minimal so I'm just going to close this.

@pkoenig10 pkoenig10 closed this Sep 13, 2021
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.

None yet

4 participants