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

tools: Include all touched packages in code coverage #673

Merged

Conversation

shahzadlone
Copy link
Member

@shahzadlone shahzadlone commented Jul 26, 2022

Relevant issue(s)

Resolves #672

Description

Ensures the empty packages aren't left out (because previously packages with 0 tests won't be included in the coverage). This should help avoid seeing the random coverage drops we see in PRs that are actually introducing tests.

Moreover:

  • Removes the make rule make test:coverage-quick.
  • Change make rule make test:coverage-full to make test:coverage
  • Adds the ability to also provide path=... to make test:coverage like we had for make test:coverage-html.
  • Account for integration test coverage for the rule make test:coverage-html.

Limitation

Using -coverpkg does not actually help if the package is never called in any test at all. -coverpkg is a cover-up that allows packages from a different package to provide coverage for this package.
So, say package a has no tests, and thus no coverage. But package b has tests, and those tests call into a. As a result, if you start using a -coverpkg that covers both packages, the tests from package b will report its coverage of package a as coverage for a.
However, if we have a package c that is never called by either a or b then that package will still be left out in the dry, even if it would match the -coverpkg given.
Reference: golang/go#24570

Tasks

  • I made sure the code is well commented, particularly hard-to-understand areas.
  • I made sure the repository-held documentation is changed accordingly.
  • I made sure the pull request title adheres to the conventional commit style (the subset used in the project can be found in tools/configs/chglog/config.yml).
  • I made sure to discuss its limitations such as threats to validity, vulnerability to mistake and misuse, robustness to invalidation of assumptions, resource requirements, ...

How has this been tested?

Individually tested all changed / updated make rules. CI will also need to pass (specially codecov action).

Specify the platform(s) on which this was tested:

  • Manjaro

@shahzadlone shahzadlone added area/testing Related to any test or testing suite ci/build This is issue is about the build or CI system, and the administration of it. code quality Related to improving code quality labels Jul 26, 2022
@shahzadlone shahzadlone added this to the DefraDB v0.3 milestone Jul 26, 2022
@shahzadlone shahzadlone self-assigned this Jul 26, 2022
@shahzadlone shahzadlone force-pushed the lone/tools/include-tests-with-no-tests-in-coverage branch from 7e79016 to ff7cfc7 Compare July 26, 2022 09:59
@shahzadlone shahzadlone force-pushed the lone/tools/include-tests-with-no-tests-in-coverage branch from ff7cfc7 to 8f0f41e Compare July 26, 2022 10:04
@orpheuslummis
Copy link
Contributor

Code coverage is a metric we should optimize (to some extent). It’s good to improve our measurement of it.

@shahzadlone shahzadlone requested a review from a team July 26, 2022 10:07
@sourcenetwork sourcenetwork deleted a comment from source-devs Jul 26, 2022
@sourcenetwork sourcenetwork deleted a comment from source-devs Jul 26, 2022
@shahzadlone shahzadlone added the action/no-benchmark Skips the action that runs the benchmark. label Jul 26, 2022
@sourcenetwork sourcenetwork deleted a comment from source-devs Jul 26, 2022
# Example: `make test:coverage-html path="./api/..."`
.PHONY: test\:coverage-html
test\:coverage-html:
@$(MAKE) test:coverage path=$(path)
Copy link
Member Author

Choose a reason for hiding this comment

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

request: If someone with iOS can test that these two commands for me, it will be bless...
make test:coverage-html path="./api/..."
and
make test:coverage-html

@orpheuslummis @fredcarle

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

first command opens this webpage directly in browser (zipped to be included as attachment here)

Copy link
Contributor

Choose a reason for hiding this comment

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

http Go Coverage Report full.html.zip

here is for second command

Copy link
Collaborator

Choose a reason for hiding this comment

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

@shahzadlone I'm not sure I can run this on my iPhone 😜

Copy link
Contributor

Choose a reason for hiding this comment

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

first command opens this webpage directly in browser (zipped to be included as attachment here)

was this default behavior pre-this PR on MacOS ? On Linux it doesn't do that for me.

Yes it was doing it pre-PR as well

Copy link
Member Author

Choose a reason for hiding this comment

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

Wow interesting! was not the default behavior on linux before, nor is now. Actually I do like that approach better, will see if can make that the default behavior for linux and mac in both cases.

Open a web browser displaying annotated source code:
        go tool cover -html=c.out

Write out an HTML file instead of launching a web browser:
        go tool cover -html=c.out -o coverage.html

Copy link
Contributor

Choose a reason for hiding this comment

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

In Linux, there is the freedesktop standards giving xdg-open that can open a default/configured browser. It is well established, but can't be assumed to be the case. On macOS it can be assumed that open is present.

Copy link
Member Author

Choose a reason for hiding this comment

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

In Linux, there is the freedesktop standards giving xdg-open that can open a default/configured browser. It is well established, but can't be assumed to be the case. On macOS it can be assumed that open is present.

Yes that is a good point! I see this to be OK the way it is as it is preserving the previous behavior.

Copy link
Member Author

Choose a reason for hiding this comment

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

@fredcarle can you confirm the error below (from discord) isn't happening in this PR anymore?

make test:coverage-html
gotestsum -- ./... -v -race -shuffle=on -coverprofile=coverage.out
make: gotestsum: No such file or directory

@orpheuslummis
Copy link
Contributor

This PR will affect the codecov bot report positively?

@orpheuslummis
Copy link
Contributor

By itself, the PR LGTM.

@shahzadlone
Copy link
Member Author

shahzadlone commented Jul 27, 2022

This PR will affect the codecov bot report positively?

Not sure what you mean by positively. What this will do is not ignore any packages that don't have tests, which would help avoid the situation of not knowing the "true" coverage. This helps eliminate the random cases where someone who writes a test for a package with no tests, but ends up with an overall lower coverage. Moreover, there is an edge case where a package might still not be included, you can read the Limitation section I added just now in PR description for more info.

@orpheuslummis
Copy link
Contributor

orpheuslummis commented Jul 27, 2022

Oops sorry for my unclear wording. I was unsure about whether it would affect the codecov, but I just re-read the Upload coverage to Codecov and that settles my question.

In light of reading your comment and the limitation section, it may be more accurate to name the commit Include all touched packages in code coverage or so? I might be misunderstanding.

@shahzadlone shahzadlone changed the title tools: Include all packages in code coverage tools: Include all touched packages in code coverage Jul 27, 2022
@shahzadlone
Copy link
Member Author

Oops sorry for my unclear wording. I was unsure about whether it would affect the codecov, but I just re-read the Upload coverage to Codecov and that settles my question.

In light of reading your comment and the limitation section, it may be more accurate to name the commit Include all touched packages in code coverage or so? I might be misunderstanding.

Done.

Copy link
Collaborator

@fredcarle fredcarle left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@shahzadlone shahzadlone merged commit 8139204 into develop Jul 28, 2022
@shahzadlone shahzadlone deleted the lone/tools/include-tests-with-no-tests-in-coverage branch July 28, 2022 07:16
shahzadlone added a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
Resolves sourcenetwork#672 

**Description:**

Ensures the empty packages aren't left out (because previously packages with 0 tests won't be included in the coverage). This should help avoid seeing the random coverage drops we see in PRs that are actually introducing tests.

__Moreover__
- Removes the make rule `make test:coverage-quick`.
- Change make rule `make test:coverage-full` to `make test:coverage`
- Adds the ability to also provide `path=...` to `make test:coverage` like we had for `make test:coverage-html`.
- Account for integration test coverage for the rule `make test:coverage-html`.

__Limitation__
Using `-coverpkg` does not actually help if the package is never called in any test at all. `-coverpkg` is a cover-up that allows packages from a different package to provide coverage for this package.
So, say package `a` has no tests, and thus no coverage. But package `b` has tests, and those tests call into `a`. As a result, if you start using a `-coverpkg` that covers both packages, the tests from package `b` will report its coverage of package `a` as coverage for `a`.
However, if we have a package `c` that is never called by either `a` or `b` then that package will still be left out in the dry, even if it would match the `-coverpkg` given.
Reference: golang/go#24570
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/no-benchmark Skips the action that runs the benchmark. area/testing Related to any test or testing suite ci/build This is issue is about the build or CI system, and the administration of it. code quality Related to improving code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Code coverage randomly drops when it includes folders that had no tests before
3 participants