Repository navigation
[ci] Keep coverage when a failed test is rerun - #1521
Merged
Merged
Conversation
gotestsum --rerun-fails reruns a failed test with the same -coverprofile, so the rerun overwrites the whole run's coverage with that one test's. The job still passes, and SonarCloud then fails the new code coverage gate with 0%. Collect coverage in a directory (-test.gocoverdir) instead, which accumulates across runs, and convert it to cover.out in a separate step.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In the ubuntu job, `gotestsum --rerun-fails` reruns a failed test with the same `-coverprofile=cover.out`, so the rerun overwrites the whole run's coverage with that one test's. The job still passes (the rerun succeeded), and SonarCloud then fails the new code coverage gate with 0%. Seen on #1517, where a flaky `TestStartProbesWithJitter` led to 136 of 136 new lines reported as uncovered.
This collects coverage in a directory instead (`-args -test.gocoverdir`), which accumulates across runs, and converts it to `cover.out` in a separate step. That step runs even when the tests fail, so a failing run still gets analyzed, as before.
Tested locally:
One difference: packages with no test files are no longer listed in `cover.out` (`-coverprofile` listed them at 0%). In the packages I ran, those were all `proto` packages and `prober/cmd`, which `sonar.coverage.exclusions` already excludes. The overall coverage number on this PR's SonarCloud run is worth a look to confirm nothing else moved.