Skip to content

Comments

Set reuseForks to true for unit tests, false for ITs#2007

Merged
Manno15 merged 2 commits intoapache:mainfrom
Manno15:jira_2781
Apr 9, 2021
Merged

Set reuseForks to true for unit tests, false for ITs#2007
Manno15 merged 2 commits intoapache:mainfrom
Manno15:jira_2781

Conversation

@Manno15
Copy link
Contributor

@Manno15 Manno15 commented Apr 8, 2021

Fixes #2015 .

This sets the reuseForks flag in maven to 'true' for unit tests while keeping it 'false' for ITs. There are some unit tests that fail with this change so they have been excluded directly in the pom file.

Though unit tests pass consistently now, there may be others that are affected by this change and may need to be investigated further.

Copy link
Member

@ctubbsii ctubbsii left a comment

Choose a reason for hiding this comment

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

Overall looks good. I recommend creating separate properties for surefire/failsafe, as in #1756, though, so it can be easily disabled.

The main question I have is: is it worth it? What's the difference in the total test runtime with reuseForks turned off and turned on? (mvn clean package runtime)

@ctubbsii ctubbsii added build enhancement This issue describes a new feature, improvement, or optimization. labels Apr 8, 2021
@Manno15
Copy link
Contributor Author

Manno15 commented Apr 9, 2021

The main question I have is: is it worth it? What's the difference in the total test runtime with reuseForks turned off and turned on? (mvn clean package runtime)

Github actions seems to show roughly have the time of completion for the unit-test portion. ~14m down to ~7-8 min. Locally, due to me running the tests in parallel, I only save roughly ~1 min. ~6min to ~5min.

* Create a profile to be able to set both values from either false or true
@Manno15 Manno15 merged commit 7957d67 into apache:main Apr 9, 2021
@Manno15 Manno15 deleted the jira_2781 branch April 9, 2021 16:32
@ctubbsii
Copy link
Member

ctubbsii commented Apr 9, 2021

@Manno15 This change actually broke the build. The exclude/include strategy won't work without renaming the tests or relocating the package they are in, because the maven-failsafe-plugin cannot load test classes from test jars that exist in the same package as classes loaded from the non-test jars, due to jar sealing violations. Unit tests run by maven-surefire-plugin don't have this problem because it doesn't load classes from jars, but from the target/classes directory (since it runs before the jars are built at the package phase).

See https://docs.oracle.com/javase/tutorial/deployment/jar/sealman.html for more info about jar sealing.

@Manno15 Manno15 restored the jira_2781 branch April 9, 2021 19:02
@Manno15
Copy link
Contributor Author

Manno15 commented Apr 9, 2021

@ctubbsii That is my mistake. I will take a look at this next week. My apologies.

@ctubbsii
Copy link
Member

ctubbsii commented Apr 9, 2021

No problem. I knew about this possibility, but it didn't occur to me to bring it up before.

@Manno15 Manno15 deleted the jira_2781 branch April 12, 2021 11:00
@Manno15
Copy link
Contributor Author

Manno15 commented Apr 12, 2021

@ctubbsii What do you think the most appropriate solution would be? Remove the exclude/include and simply rename the packages to an 'IT' variant or keep the include/exclude just to list the ones that break the build and then either rename or move them? I noticed at least one of the tests will have issues with moving based on a class it depends on.

@ctubbsii
Copy link
Member

@Manno15 Either way, in order to avoid jar sealing violations, they will need to be moved to a package (or packages) that does not exist in the regular, non-test jars. If you want to keep the current names, so you have a list of excludes/includes to track, that's fine. But rename or not, they do need to be in different packages if they are being run by failsafe instead of surefire.

asfgit pushed a commit that referenced this pull request Apr 13, 2021
Set reuseForks=false for maven-surefire-plugin and remove
includes/excludes added to maven-surefire-plugin and
maven-failsafe-plugin as part of #2007 to avoid build failures.

These were originally implemented to speed up the build, and the
includes/excludes were implemented to force some tests that didn't
behave well in a reused fork to run in their own fork as an IT instead
of as a unit test. However, that breaks jar sealing and some tests are
hard to relocate to a different package without cascading impacts.

So, the workaround for these tests are disabled by default until a
workaround for those test failures can be addressed in a different way,
but can be manually re-enabled by setting the appropriate flag..
@ctubbsii
Copy link
Member

@Manno15 Okay, so, I did a partial revert, changing the default value for reuseForks to false for surefire, and removing the includes/excludes, just to get things working again, so we can get other PRs merged. If some tests can be renamed to the *IT pattern, and placed in a different (sub)package, then that's one option. Another option would be to run an extra execution of maven-surefire-plugin for just those tests, with reuseForks specifically turned off (similar to how minicluster/pom.xml forces forkCount to be 1). However, it may be okay just to leave this configurable for now, and set the default value to true later, after further improvements. I'm not sure how much work any of these options are.

@Manno15
Copy link
Contributor Author

Manno15 commented Apr 13, 2021

I will investigate further. The extra execution of surefire is interesting. Either way, having it configurable is a good place to be in the meantime. Thanks for taking a look and doing the partial revert @ctubbsii

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

Labels

build enhancement This issue describes a new feature, improvement, or optimization.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants