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

[Enchancement] Removed dependency between "test" and "jacocoTestReport" #2935

Merged

Conversation

pawel-gudel-eliatra
Copy link
Contributor

Description

As a part of discussions in #2861 there's been determined that CI workflow in Github Actions is excluding a lot of unnecessary task. @nibix created #2913 to address this problem. Most of the unneeded tasks has been already removed in #2861. This PR removes last existing part. @peternied's confirmed removal of dependency in his comment.

This change removes the dependency between "jacocoTestReport" and "test" tasks. Specifically the dependency that forces to start "test" task always when "jacocoTestReport" is called. This allows us to always generate coverage report in the end of every task run in "CI" workflow without having to exclude "test" task in every single one of them. Unfortunately this will break functionality to create code coverage by starting only "jacocoTestReport" task. It looks like this was not used widely and was certainly not used in any of Github Actions Workflows. This will not break creating coverage reports in the end of "test" task.

Issues Resolved

#2913

Testing

Manual tests been done to verify that output is in line with expectations. No tests are being added nor are needed.

Check List

  • New functionality includes testing
  • New functionality has been documented
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Closes issue opensearch-project#2913.

This will allow us to not to exclude the "test" job from every other test.

Unfortunately, this will break creating the coverage reports from only starting "jacocoTestReport" task in Gradle.

Signed-off-by: Pawel Gudel <[email protected]>
@codecov
Copy link

codecov bot commented Jul 5, 2023

Codecov Report

Merging #2935 (ec88d2b) into main (4eef662) will decrease coverage by 0.53%.
The diff coverage is n/a.

@@             Coverage Diff              @@
##               main    #2935      +/-   ##
============================================
- Coverage     62.31%   61.78%   -0.53%     
+ Complexity     3337     3306      -31     
============================================
  Files           266      266              
  Lines         19650    19650              
  Branches       3329     3329              
============================================
- Hits          12244    12141     -103     
- Misses         5779     5873      +94     
- Partials       1627     1636       +9     

see 13 files with indirect coverage changes

@@ -390,8 +390,6 @@ tasks.withType(JavaCompile) {
}

tasks.test.finalizedBy(jacocoTestReport) // report is always generated after tests run
tasks.jacocoTestReport.dependsOn(test) // tests are required to run before generating the report
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this is the right thing to do: Gradle uses build cache (see please [1]) which should run test task only once. The build essentially becomes unusable for regular contributors since they have to closely follow whatever the GA workflow does, not just run ./gradlew check and get the code coverage.

[1] https://docs.gradle.org/current/userguide/build_cache.html#sec:task_output_caching_details

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately I do not understand the issue here. Running ./gradlew check does not disable creation of code coverage report. Output below:

root@8aadb8ef940c:/app# ./gradlew check --dry-run
=======================================
OpenSearch Build Hamster says Hello!
  Gradle Version        : 8.1.1
  OS Info               : Linux 6.3.8-200.fc38.x86_64 (amd64)
  JDK Version           : 17 (Eclipse Temurin JDK)
  JAVA_HOME             : /root/.sdkman/candidates/java/17.0.7-tem
  Random Testing Seed   : 41734A7976B6C119
  In FIPS 140 mode      : false
=======================================
:compileJava SKIPPED
:processResources SKIPPED
:classes SKIPPED
:compileIntegrationTestJava SKIPPED
:processIntegrationTestResources SKIPPED
:integrationTestClasses SKIPPED
:checkstyleIntegrationTest SKIPPED
:checkstyleMain SKIPPED
:compileTestJava SKIPPED
:copyPluginPropertiesTemplate SKIPPED
:pluginProperties SKIPPED
:processTestResources SKIPPED
:testClasses SKIPPED
:checkstyleTest SKIPPED
:forbiddenApisResources SKIPPED
:forbiddenApisIntegrationTest SKIPPED
:forbiddenApisMain SKIPPED
:forbiddenApisTest SKIPPED
:forbiddenApis SKIPPED
:dependencyLicenses SKIPPED
:filepermissions SKIPPED
:forbiddenPatterns SKIPPED
:jarHell SKIPPED
:licenseHeaders SKIPPED
:loggerUsageCheck SKIPPED
:testingConventions SKIPPED
:thirdPartyAuditResources SKIPPED
:thirdPartyAudit SKIPPED
:generatePomFileForMavenPublication SKIPPED
:generatePomFileForNebulaPublication SKIPPED
:generatePomFileForPluginZipPublication SKIPPED
:validateMavenPom SKIPPED
:validateNebulaPom SKIPPED
:validatePluginZipPom SKIPPED
:validatePom SKIPPED
:precommit SKIPPED
:integTest SKIPPED
:copyExtraTestResources SKIPPED
:test SKIPPED
:integrationTest SKIPPED
:javadoc SKIPPED
:spotbugsIntegrationTest SKIPPED
:spotbugsMain SKIPPED
:spotbugsTest SKIPPED
:spotlessInternalRegisterDependencies SKIPPED
:spotlessJava SKIPPED
:spotlessJavaCheck SKIPPED
:spotlessMisc SKIPPED
:spotlessMiscCheck SKIPPED
:spotlessCheck SKIPPED
:jacocoTestReport SKIPPED
:check SKIPPED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/8.1.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 1s

When you start test the code coverage ("jacocoTestReport" task) is always started. This PR only removed reverse dependency: a situation when running ./gradlew jacocoTestReport also forces test to be run.

Copy link
Collaborator

@reta reta Jul 11, 2023

Choose a reason for hiding this comment

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

Running ./gradlew check does not disable creation of code coverage report.

And

When you start test the code coverage ("jacocoTestReport" task) is always started.

That is coming from:

tasks.test.finalizedBy(jacocoTestReport) // report is always generated after tests run

This PR only removed reverse dependency: a situation when running ./gradlew jacocoTestReport also forces test to be run.

Exactly, and this is my question - the jacocoTestReport by definition needs test to be run (otherwise there is no input to build the report), so if one runs ./gradlew jacocoTestReport it would make sense to have tests to be run before

However, if ones run those two in sequence

./gradlew test
./gradlew jacocoTestReport

The jacocoTestReport should not cause test to be rerun

Copy link
Contributor Author

@pawel-gudel-eliatra pawel-gudel-eliatra Jul 17, 2023

Choose a reason for hiding this comment

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

Unfortunately I still do not quite understand issue here. I'll try to answer one-by-one:

Exactly, and this is my question - the jacocoTestReport by definition needs test to be run (otherwise there is no input to build the report)

Yes, it needs to be run but not as a separate task. It is run always after the "test" task.

so if one runs ./gradlew jacocoTestReport it would make sense to have tests to be run before

What should make sense is to start "test", not "jacocoTestReport".

However, if ones run those two in sequence
./gradlew test
./gradlew jacocoTestReport
The jacocoTestReport should not cause test to be rerun

This is not the scope of this PR. I don't understand why would you like to "jacocoTestReport" as a separate task after running "test" ("jacocoTestReport" is always started after "test" already!). In your execution of two command Gradle runs following things:

  1. (on current master): "test" -> "jacocoTestReport" -> "test" -> jacocoTestReport"
  2. (on my PR): "test" -> "jacocoTestReport" -> "jacocoTestReport"

Why would someone like to do that? Just run "./gradlew test" once and get both "test" and "jacocoTestReport" in the same run.

Also, I've verified and "check" job starts "jacocoTestReport" but only as a part of "test" job. This PR does not break creation of code coverage by running "check" task.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@peternied adding you as discussed

From our point of view

./gradlew test

is the only thing a dev on their local system would need. Not sure if we are missing something.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not the scope of this PR. I don't understand why would you like to "jacocoTestReport" as a separate task after running "test" ("jacocoTestReport" is always started after "test" already!). In your execution of two command Gradle runs following things:

I think this is the core of the issue:

  • the test does not need jacocoTestReport (one could run tests without coverage)
  • the jacocoTestReport needs test (one needs tests for the reports)

Why would someone like to do that? Just run "./gradlew test" once and get both "test" and "jacocoTestReport" in the same run.

I think removing this dependency would make sense

tasks.test.finalizedBy(jacocoTestReport)

but not the dependency between test and jacocoTestReport

Copy link
Collaborator

Choose a reason for hiding this comment

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

is the only thing a dev on their local system would need. Not sure if we are missing something.

@nibix if ./gradlew test assumes tests and coverage report (which at least in OpenSearch core is two separated tasks at the moment), than the change is fine.

Copy link
Member

Choose a reason for hiding this comment

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

I would recommend that executing tests is separate from the generation of a coverage report. As we have many checks that are only defined by GitHub Actions.

I've created an issue to track this area and to solict more feedback.

@stephen-crawford
Copy link
Contributor

Hi @pawel-gudel-eliatra, just checking in on the status of this PR. Is there anything you need help with to wrap this up? @reta, did you get a chance to review @pawel-gudel-eliatra's response above? Thank you both.

@reta
Copy link
Collaborator

reta commented Jul 11, 2023

@reta, did you get a chance to review @pawel-gudel-eliatra's response above? Thank you both.

Oh ... I totally missed that response, my sincere apologies, let me look into that right now

@nibix
Copy link
Collaborator

nibix commented Aug 7, 2023

@reta @peternied I just wanted to double-check: After filing #3045, shall we wait for feedback coming via that issue? Or how shall we proceed here?

Copy link
Member

@peternied peternied left a comment

Choose a reason for hiding this comment

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

I think this change is an improvement, I approve

Copy link
Member

@DarshitChanpura DarshitChanpura left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you @pawel-gudel-eliatra !

From what I understand, this PR prevents circular dependency between jacocoTestReport and test task allowing test to not be skipped in Build and Test step of CI.

@DarshitChanpura DarshitChanpura merged commit 32d3112 into opensearch-project:main Aug 17, 2023
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.

6 participants