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

Fixes executionData file getting overridden #21

Merged
merged 1 commit into from
Jul 14, 2021
Merged

Fixes executionData file getting overridden #21

merged 1 commit into from
Jul 14, 2021

Conversation

gmazzo
Copy link
Contributor

@gmazzo gmazzo commented Jul 13, 2021

This PR addresses the being discussed here gradle/gradle#16603 (comment) regarding Gradle's Build Cache failing to pack an entry.

The root cause is a race condition caused by this plugin, because the execution data is getting feed (and overridden) by two Jacoco agents: the one from the Test class and the other one that runs inside it with a GradleRunner.

The fixing approach is to create a companion execution data file and make it's associated JacocoReport task to also feed from it.

}.get()
)
it.outputFile = File(buildDir, "/testkit/${taskProvider.name}/testkit-gradle.properties")
it.destinationFile.set(destinationFile.get().path) // .get() breaks the circular dependency
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if this .get() was intentional but my natural approach to this will be:

it.destinationFile.set(destinationFile.map(File::getPath))

The problem is that also adds a dependency from jacocoTestKitPropertiesTask to taskProvider and as later we do:

taskProvider.configure { it.dependsOn(jacocoTestKitPropertiesTask) }

a circular dependency is form.

Copy link
Owner

Choose a reason for hiding this comment

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

There is even a comment in this line // .get() breaks the circular dependency

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The comment was to state that without a .get() that breaks the dependency inference of the Property API, a dependency loop is made.

Anyway I've just removed it.

@koral--
Copy link
Owner

koral-- commented Jul 13, 2021

Unit tests are failing on Bitrise CI:

> Task :test
pl.droidsonroids.gradle.jacoco.testkit.JaCoCoTestKitPluginFunctionalTest > gradle properties file generated with explicit version FAILED
    org.gradle.testkit.runner.UnexpectedBuildFailure at JaCoCoTestKitPluginFunctionalTest.kt:52
pl.droidsonroids.gradle.jacoco.testkit.JaCoCoTestKitPluginFunctionalTest > gradle properties file generated for a custom task FAILED
    org.gradle.testkit.runner.UnexpectedBuildFailure at JaCoCoTestKitPluginFunctionalTest.kt:133
pl.droidsonroids.gradle.jacoco.testkit.JaCoCoTestKitPluginFunctionalTest > gradle properties file generated with default version FAILED
    java.lang.AssertionError at JaCoCoTestKitPluginFunctionalTest.kt:41
pl.droidsonroids.gradle.jacoco.testkit.JaCoCoTestKitPluginFunctionalTest > plugin compatible with Gradle 4_9 FAILED
    org.gradle.testkit.runner.UnexpectedBuildFailure at JaCoCoTestKitPluginFunctionalTest.kt:95
pl.droidsonroids.gradle.jacoco.testkit.JaCoCoTestKitPluginFunctionalTest > gradle properties file generated doesn't change between builds FAILED
    org.gradle.testkit.runner.UnexpectedBuildFailure at JaCoCoTestKitPluginFunctionalTest.kt:72
pl.droidsonroids.gradle.jacoco.testkit.JaCoCoTestKitPluginFunctionalTest > gradle properties file generated with custom destination file FAILED
    org.gradle.testkit.runner.UnexpectedBuildFailure at JaCoCoTestKitPluginFunctionalTest.kt:118
pl.droidsonroids.gradle.jacoco.testkit.JaCoCoTestKitPluginFunctionalTest > plugin compatible with Instant Execution FAILED
    org.gradle.testkit.runner.UnexpectedBuildFailure at JaCoCoTestKitPluginFunctionalTest.kt:107

@gmazzo
Copy link
Contributor Author

gmazzo commented Jul 13, 2021

Unit tests are failing on Bitrise CI:

Just fixed them

@codecov-commenter
Copy link

codecov-commenter commented Jul 13, 2021

Codecov Report

Merging #21 (08ec9f9) into master (93454df) will decrease coverage by 1.57%.
The diff coverage is 87.50%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master      #21      +/-   ##
============================================
- Coverage     92.68%   91.11%   -1.58%     
  Complexity        8        8              
============================================
  Files             4        4              
  Lines            41       45       +4     
  Branches          2        3       +1     
============================================
+ Hits             38       41       +3     
  Misses            2        2              
- Partials          1        2       +1     
Impacted Files Coverage Δ
...ds/gradle/jacoco/testkit/JacocoTestKitExtension.kt 90.00% <87.50%> (-3.75%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 93454df...08ec9f9. Read the comment docs.

it.jacocoRuntimePath.set(jacocoRuntimePathProvider)
}

dependencies.add(configurationRuntime, files(testKitDir(taskProvider.name)))
taskProvider.configure { it.dependsOn(jacocoTestKitPropertiesTask) }

tasks.withType(JacocoReport::class.java)
.matching { it.name == "jacoco${taskProvider.name.capitalize()}Report" }
Copy link
Owner

Choose a reason for hiding this comment

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

If provider name starts with i and default locale at runtime is set to Turkish or Azeri then capitalization will result in capital dotted İ so no match will be probably found.
Anyway we have a similar existing capitalize https://github.com/koral--/jacoco-gradle-testkit-plugin/pull/15#discussion_r418568736 so it's fine for now to leave it also here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually this was the most controversial part of the change, as I generally don't like reference tasks by name miming their internal plugin logic to name them. But I couldn't find a way to archive this without making too much refactor on the current code.

@koral-- koral-- merged commit efe3bb9 into koral--:master Jul 14, 2021
@gmazzo gmazzo deleted the fix-execution-data-clash branch July 14, 2021 10:20
@gmazzo
Copy link
Contributor Author

gmazzo commented Jul 14, 2021

Do you have any plans to do a new release? I have an internal PR blocked due to this. Actually I did a workaround, but it would be nice just to point to the latest version :)

@gmazzo
Copy link
Contributor Author

gmazzo commented Jul 21, 2021

Hi @koral-- , I've noted this seems to be incompable with Build Cache. I'll be resarching how to get it work.

The two files are there when the test task runs: test.exec and test-gradle-runner.exec. But when it's FROM-CACHE only test.exec is the jacoco folder.

I've tried adding:

tasks.withType<Test> {
     outputs.file("$buildDir/jacoco/$name-gradle-runner.exec")
}

But still now working 🤔

koral-- pushed a commit that referenced this pull request Aug 10, 2021
* Revert "Fixes `executionData` file getting overridden (#21)"

This reverts commit efe3bb9.

* Applies `jacoco` plugin by default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants