Skip to content

[ci] Keep coverage when a failed test is rerun - #1521

Merged
manugarg merged 1 commit into
mainfrom
ci-coverage-survives-reruns
Oct 4, 2026
Merged

manugarg merged 1 commit into
mainfrom
ci-coverage-survives-reruns

Conversation

@manugarg

@manugarg manugarg commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

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:

  • A toy module with a test that fails only once: the old command leaves every line at 0 in `cover.out` after the rerun; the new one gives the full coverage, with the rerun's counts merged in.
  • `./metrics/... ./prober/... ./common/...` in this repo: the new command gives the same profile as the old one, apart from the difference below.

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.

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.
@manugarg
manugarg merged commit 29ce66f into main Oct 4, 2026
13 checks passed
@manugarg
manugarg deleted the ci-coverage-survives-reruns branch October 4, 2026 09:10
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.

1 participant