-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Support the build cache and parallel test execution with the JaCoCo plugin applied #5269
Comments
We would love to change the default for |
There is also another problem: When using parallel test execution. We don't know if |
If you are willing to work on a solution in the JaCoCo plugin to support parallel test execution with caching and the Jacoco plugin enabled, then we would be happy to assist you in building the corresponding PR. I think the basic approach would be to interpret
We would need some test coverage making sure that parallel test execution works well with the Jacoco plugin and When this works, we would set |
@wolfs If we're making a breaking change in 5.0, we may also just want to remove configuration options that don't make sense or make it difficult to do the right thing. Even though there's a |
@wolfs What about simply having each worker generate their own JaCoCo report? We do that here at Plexxi to create our uber coverage report from all of our sub-projects. val jacocoRootReport = task<JacocoReport>("jacocoRootReport") {
group = LifecycleBasePlugin.VERIFICATION_GROUP
description = "Generates code coverage report for all sub-projects."
val jacocoReportTasks =
subprojects
.filter {
// Filter out source sets that don't have tests in them
// Otherwise, Jacoco tries to generate coverage data for tests that don't exist
!it.java.sourceSets["test"].allSource.isEmpty
}
.map { it.tasks[jacocoTestResultTaskName] as JacocoReport }
dependsOn(jacocoReportTasks)
val allExecutionData = jacocoReportTasks.map { it.executionData }
executionData(*allExecutionData.toTypedArray())
// Pre-initialize these to empty collections to prevent NPE on += call below.
additionalSourceDirs = files()
sourceDirectories = files()
classDirectories = files()
subprojects.forEach { testedProject ->
val sourceSets = testedProject.java.sourceSets
this@task.additionalSourceDirs = this@task.additionalSourceDirs?.plus(files(sourceSets["main"].allSource.srcDirs))
this@task.sourceDirectories += files(sourceSets["main"].allSource.srcDirs)
this@task.classDirectories += files(sourceSets["main"].output)
}
reports {
html.isEnabled = true
xml.isEnabled = true
csv.isEnabled = false
}
} |
Is there a |
I did some digging and it seems like the JaCoCo agent locks the exec file before writing to it. It writes the execution data to the file when the JVM shuts down. See jacoco/jacoco#52. As a consequence, I think the plan I described above would be good. We could also deprecate setting @big-guy Do you suggest removing the @JLLeitschuh There is no 5.0 branch but I think the changes I described above can be implemented in |
@big-guy @w4tson The implications of this bug are a bit wider reaching than originally captured by this bug. Gathering from what you've stated here, it seems that if you choose to have multiple workers for your tests, and you want to capture Jacoco code-coverage data, there is no way to also get build cache support. So your options are, build cache support, or tests on multiple workers, but not both. Does this merit another issue being opened as this implication seems to be of slightly wider concern than this issue originally tried to capture? |
@JLLeitschuh You are exactly right. When using the java and jacoco plugins, users have the complicated and unclear choice of...
It would be better if someone could have jacoco analysis, parallel test execution, Test cacheability -- all by default or easily configurable. I wouldn't open a new issue but change the name of the current issue. I gave the rename a shot. WDYT? |
I think that the new names captures it quite well, I updated the top comment on the issue to link to your comment @wolfs. |
@wolfs Unfortunately, I don't think I'm going to have the time to fix this myself. Is there any possibility that someone from the team will get the chance to tackle this before |
Hi! Talking about gradle 4.7: From reading the above I got the expression that
should work if I don't care for the test cache, right? How can I verify that the test cache is disabled? Is writing to different report files per agent supported yet? Cal |
According to this issue The build cache is disabled if you didn't explicitly enable it and it will be disabled for all I don't know about any issue regarding using parallel forks and Writing different report files per test worker is not supported, yet. The build cache shouldn't have any effect on whether tests are executed or not. Are you talking about single tests within the same |
Thanks for your answer. It's a test job of about 8000 tests. Last time less then 2000 tests were executed. So whole testsuites in junit jargon are missing. |
@cal101 That sounds like a bug. Could you open another issue with some instructions how to reproduce the problem? |
@wolfs I will try to make a reproducible case but that's difficult. It's on a closed source legacy project. It may be easier for me trying to debug the issue. I will start trying to debug. |
Jacoco code coverage should work well with the build cache out of the box. Since appending to a coverage file works with parallel test execution, see jacoco/jacoco#52, we set `append=true` and delete the coverage data just before the test task starts to execute. Note that this is a breaking change: separate tasks now cannot use the same coverage file, since each of the tasks will delete it. Issue: #5269
Fixed via #6419. |
@wolfs Thank you for fixing this!!! Is |
Jacoco append property is deprecated starting gradle 5.0. From my understandind the propery is currently ignored. [Issue Ref](gradle/gradle#5269) Signed-off-by: Bhargava Varadharajan <[email protected]>
Hi Every one , i want for one test case , only single exec file is generated having mapping of java classes which are touched by this tests case only. (this is possible , if i execute test cases in serial). In order to save time, i want to execute multiple test cases at same time, and in exec only those java classes covered which is touched by test case specific to it. Is there any way to achieve this ? |
The work-around introduced in b182fc3 is not required anymore as of Gradle 5.0, see [1]. [1]: gradle/gradle#5269 Signed-off-by: Sebastian Schuberth <[email protected]>
The work-around introduced in b182fc3 is not required anymore as of Gradle 5.0, see [1]. [1]: gradle/gradle#5269 Signed-off-by: Sebastian Schuberth <[email protected]>
Update
The wider implications of this bug is captured well here:
#5269 (comment)
Expected Behavior
If you use the Jacoco plugin with it's default configuration, it should not break the
Test
task's ability to be cached.Current Behavior
Applying the
Jacoco
plugin to your project makes theTest
task not support caching.gradle/subprojects/jacoco/src/main/java/org/gradle/testing/jacoco/plugins/JacocoPluginExtension.java
Lines 131 to 136 in 76387d9
https://docs.gradle.org/current/dsl/org.gradle.testing.jacoco.plugins.JacocoTaskExtension.html#org.gradle.testing.jacoco.plugins.JacocoTaskExtension:append
Context
It makes sense that if you have custom configuration for the
Jacoco
plugin you might prevent Build Caching from working, but in it's default configuration it should work.Steps to Reproduce (for bugs)
Add the
Jacoco
plugin to a project and be using the Build Cache.Workaround
Using the Kotlin DSL:
Your Environment
The text was updated successfully, but these errors were encountered: