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

Add unit test coverage requirements for some packages #22401

Closed

Conversation

lunny
Copy link
Member

@lunny lunny commented Jan 11, 2023

This PR add a CI check for package tests coverage. When the coverage is less than a previous value, CI will be failure.

@lunny lunny added the topic/build PR changes how Gitea is built, i.e. regarding Docker or the Makefile label Jan 11, 2023
@KN4CK3R
Copy link
Member

KN4CK3R commented Jan 11, 2023

I think this should use the merged results. Currently it only uses the integration test result.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jan 11, 2023
@lunny
Copy link
Member Author

lunny commented Jan 12, 2023

I think this should use the merged results. Currently it only uses the integration test result.

Done

Makefile Outdated Show resolved Hide resolved
@KN4CK3R
Copy link
Member

KN4CK3R commented Jan 16, 2023

2023/01/16 09:02:54 package code.gitea.io/gitea/modules/validation coverage is 79.4%, required 80.1%
2023/01/16 09:02:54 package code.gitea.io/gitea/modules/webhook coverage is 13.3%, required 13.7%
2023/01/16 09:02:54 package code.gitea.io/gitea/modules/svg coverage is 94.4%, required 96.1%
2023/01/16 09:02:54 package code.gitea.io/gitea/modules/doctor coverage is 15.1%, required 20.8%
2023/01/16 09:02:54 package code.gitea.io/gitea/modules/cache coverage is 14.5%, required 14.6%
2023/01/16 09:02:54 package code.gitea.io/gitea/modules/emoji coverage is 83.3%, required 85.1%
2023/01/16 09:02:54 package code.gitea.io/gitea/modules/auth coverage is NaN%, required 60.2%
2023/01/16 09:02:54 package code.gitea.io/gitea/modules/graceful coverage is 29.0%, required 29.2%
2023/01/16 09:02:54 package code.gitea.io/gitea/modules/indexer coverage is NaN%, required 39.2%
2023/01/16 09:02:54 package code.gitea.io/gitea/services/cron coverage is 56.2%, required 61.4%
2023/01/16 09:02:54 package code.gitea.io/gitea/services/forms coverage is 36.5%, required 36.8%
2023/01/16 09:02:54 package code.gitea.io/gitea/modules/proxy coverage is 17.2%, required 21.4%
2023/01/16 09:02:54 package code.gitea.io/gitea/modules/process coverage is 38.5%, required 40.2%
2023/01/16 09:02:54 package code.gitea.io/gitea/services/convert coverage is 73.5%, required 74.8%
2023/01/16 09:02:54 package code.gitea.io/gitea/modules/issue coverage is NaN%, required 75.4%
2023/01/16 09:02:54 package code.gitea.io/gitea/routers/api coverage is NaN%, required 60.6%
2023/01/16 09:02:54 package code.gitea.io/gitea/routers/install coverage is 5.7%, required 7.3%

Now we see that it works. But it looks like our code calculates the coverage different than CodeCov.

@lunny
Copy link
Member Author

lunny commented Jan 16, 2023

2023/01/16 09:02:54 package code.gitea.io/gitea/modules/validation coverage is 79.4%, required 80.1%
2023/01/16 09:02:54 package code.gitea.io/gitea/modules/webhook coverage is 13.3%, required 13.7%
2023/01/16 09:02:54 package code.gitea.io/gitea/modules/svg coverage is 94.4%, required 96.1%
2023/01/16 09:02:54 package code.gitea.io/gitea/modules/doctor coverage is 15.1%, required 20.8%
2023/01/16 09:02:54 package code.gitea.io/gitea/modules/cache coverage is 14.5%, required 14.6%
2023/01/16 09:02:54 package code.gitea.io/gitea/modules/emoji coverage is 83.3%, required 85.1%
2023/01/16 09:02:54 package code.gitea.io/gitea/modules/auth coverage is NaN%, required 60.2%
2023/01/16 09:02:54 package code.gitea.io/gitea/modules/graceful coverage is 29.0%, required 29.2%
2023/01/16 09:02:54 package code.gitea.io/gitea/modules/indexer coverage is NaN%, required 39.2%
2023/01/16 09:02:54 package code.gitea.io/gitea/services/cron coverage is 56.2%, required 61.4%
2023/01/16 09:02:54 package code.gitea.io/gitea/services/forms coverage is 36.5%, required 36.8%
2023/01/16 09:02:54 package code.gitea.io/gitea/modules/proxy coverage is 17.2%, required 21.4%
2023/01/16 09:02:54 package code.gitea.io/gitea/modules/process coverage is 38.5%, required 40.2%
2023/01/16 09:02:54 package code.gitea.io/gitea/services/convert coverage is 73.5%, required 74.8%
2023/01/16 09:02:54 package code.gitea.io/gitea/modules/issue coverage is NaN%, required 75.4%
2023/01/16 09:02:54 package code.gitea.io/gitea/routers/api coverage is NaN%, required 60.6%
2023/01/16 09:02:54 package code.gitea.io/gitea/routers/install coverage is 5.7%, required 7.3%

Now we see that it works. But it looks like our code calculates the coverage different than CodeCov.

yes, For those slight differences, I think it's accepted.

@KN4CK3R
Copy link
Member

KN4CK3R commented Jan 16, 2023

Looks like CodeCov combines the results of the subdirectories. Our calculation displays the result for the files in that directory only (?). That would explain the NaN% lines.

@6543
Copy link
Member

6543 commented Apr 2, 2023

I would lower the current requirements to match what we have atm ... and then do increase them by case

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Apr 2, 2023
@6543 6543 added this to the 1.20.0 milestone Apr 2, 2023
Makefile Outdated Show resolved Hide resolved
@silverwind
Copy link
Member

silverwind commented Apr 5, 2023

When the coverage is less than a previous value, CI will be failure

I forsee some PR friction if we add this. I'd guess more PRs than usual would become abandoned with such strict requirements as not every bug fix is easily testable. We can try, but I guess there should be a mechanism for a owner to overrule this requirement for individual PRs.

@wxiaoguang
Copy link
Contributor

Is it the right way to go?

@lunny lunny added the pr/wip This PR is not ready for review label May 1, 2023
@wxiaoguang wxiaoguang added the issue/needs-feedback For bugs, we need more details. For features, the feature must be described in more detail label May 2, 2023
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 2, 2023
@6543
Copy link
Member

6543 commented May 2, 2023

I think in worst case we can lower the number for a fix in that pull ... but we should enforce it ... we want good tested code

@wxiaoguang
Copy link
Contributor

I agree to improve test code (when I review, I frequently suggest to add tests ...)

But, is it the right way to go? Filling the Makefile with a lot of percentage numbers?

@6543
Copy link
Member

6543 commented May 2, 2023

we could improve the tool that checks it and add a new .min_coverage.conf or something like that witch do contain the threashhold

@wxiaoguang
Copy link
Contributor

A clear Makefile could L-G-T-M

@delvh delvh removed this from the 1.20.0 milestone Jun 7, 2023
@pull-request-size pull-request-size bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 13, 2023
.drone.yml Outdated Show resolved Hide resolved
@lunny lunny force-pushed the lunny/add_package_unittest_requirement branch from 7ffa15c to 495eb4a Compare June 14, 2023 11:46
@pull-request-size pull-request-size bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jun 14, 2023
if err != nil {
log.Fatalf("invalid percent: %s", percent)
}
return int64(i * 10)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why i*10 ? 12.34% means "123"? That's a strange unit.

Copy link
Member Author

Choose a reason for hiding this comment

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

Some output will be 12.3%, and I think it's accurate enough.

Copy link
Contributor

@wxiaoguang wxiaoguang Jun 15, 2023

Choose a reason for hiding this comment

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

I would say this trick is difficult to understand, and I do not understand why it must be casted to int64

IMO keep the original float "12.3" is clear enough, or unify the unit to natural unit (1.0 mean 100%, 0.02 mean 2%)

build/gocoverage.go Outdated Show resolved Hide resolved
build/gocoverage.go Outdated Show resolved Hide resolved
build/gocoverage.go Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
@silverwind
Copy link
Member

silverwind commented Jun 14, 2023

Will there be an option to ignore reduced coverage? Like when some stuff is hard/impossible to test for, e.g. admin should still be able to merge.

Generally, I'm -0 on this topic, as it may hinder contribution.

go-version: ">=1.20"
check-latest: true
- uses: actions/download-artifact@v3
- run: go run build/gocoverage.go merge unit-test-coverage/coverage.out unit-test-coverage-gogit/coverage.out unit-test-coverage-integration/coverage.out > coverage.all
Copy link
Member

@silverwind silverwind Jun 17, 2023

Choose a reason for hiding this comment

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

Calls like this should be in the Makefile so that coverage can be produced locally as well. Please don't lock us in into actions with commands like this.

@lunny
Copy link
Member Author

lunny commented Jul 14, 2023

Will there be an option to ignore reduced coverage? Like when some stuff is hard/impossible to test for, e.g. admin should still be able to merge.

Generally, I'm -0 on this topic, as it may hinder contribution.

Looks like we need to ask contributors to provide tests case by case. But should always encourage tests in PR.
So I will close this one.

@lunny lunny closed this Jul 14, 2023
@lunny lunny deleted the lunny/add_package_unittest_requirement branch July 14, 2023 08:00
@silverwind
Copy link
Member

Yes, I'm always asking where possible, I think it's the best we can do. Strict requirements will not work so good I guess.

@go-gitea go-gitea locked as resolved and limited conversation to collaborators Oct 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue/needs-feedback For bugs, we need more details. For features, the feature must be described in more detail lgtm/need 1 This PR needs approval from one additional maintainer to be merged. pr/wip This PR is not ready for review size/L Denotes a PR that changes 100-499 lines, ignoring generated files. topic/build PR changes how Gitea is built, i.e. regarding Docker or the Makefile
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants