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

*: make unit test great #7952

Merged
merged 6 commits into from Apr 10, 2024
Merged

*: make unit test great #7952

merged 6 commits into from Apr 10, 2024

Conversation

HuSharp
Copy link
Member

@HuSharp HuSharp commented Mar 20, 2024

What problem does this PR solve?

Issue Number: Ref #7969

What is changed and how does it work?

Add back parallel by run a single test case in a isolated OS process

We use a wrong way to parallel. Some test cases are not side effect free, for example:

  • the enable and disable of the failpoint
  • modification of the configuration
  • change of the global variable in a single process.
    etc...

If the test cases with side effect run parallelly with others, it could cause some test fail unexpectedly.
When they're in a single OS process, make them parallel is not a big deal.

usage

// run all tests
pd-ut

// show usage
pd-ut -h

// list all packages
pd-ut list

// list test cases of a single package
pd-ut list $package

// list test cases that match a pattern
pd-ut list $package 'r:$regex'

// run all tests
pd-ut run

// run test all cases of a single package
pd-ut run $package

// run test cases of a single package
pd-ut run $package $test

// run test cases that match a pattern
pd-ut run $package 'r:$regex'

// build all test package
pd-ut build

// build a test package
pd-ut build xxx

// write the junitfile
pd-ut run --junitfile xxx

// test with race flag
pd-ut run --race

use xprog to accelerate bin.test build

go test --exec=xprog, the Go compile toolchain would call your xprog program passing the test binary path as the argument

So you can do this trick, write you own xprog, and move the test binary to some place else, save it for later use.

print function time

when using ./pd-ut run --junitfile xxx, can get junitfile as XML file to get every function cost time.

	<testsuite tests="11" failures="0" time="1.789263" name="github.com/tikv/pd/pkg/btree">
		<properties>
			<property name="go.version" value="go1.21.0 linux/amd64"></property>
		</properties>
		<testcase classname="github.com/tikv/pd/pkg/btree" name="TestAscendLessThanG" time="0.038767"></testcase>
		<testcase classname="github.com/tikv/pd/pkg/btree" name="TestAscendGreaterOrEqualG" time="0.033858"></testcase>
		<testcase classname="github.com/tikv/pd/pkg/btree" name="TestDeleteMaxG" time="0.201940"></testcase>
		<testcase classname="github.com/tikv/pd/pkg/btree" name="TestBTreeSizeInfo" time="0.136755"></testcase>
		<testcase classname="github.com/tikv/pd/pkg/btree" name="TestDescendGreaterThanG" time="0.013433"></testcase>
		<testcase classname="github.com/tikv/pd/pkg/btree" name="TestDeleteMinG" time="0.262618"></testcase>
		<testcase classname="github.com/tikv/pd/pkg/btree" name="TestCloneConcurrentOperationsG" time="0.335037"></testcase>
		<testcase classname="github.com/tikv/pd/pkg/btree" name="TestBTreeG" time="0.348103"></testcase>
		<testcase classname="github.com/tikv/pd/pkg/btree" name="TestDescendLessOrEqualG" time="0.018799"></testcase>
		<testcase classname="github.com/tikv/pd/pkg/btree" name="TestDescendRangeG" time="0.302686"></testcase>
		<testcase classname="github.com/tikv/pd/pkg/btree" name="TestAscendRangeG" time="0.097267"></testcase>
	</testsuite>

Performance

Since we run parallel now, the CI runs faster than before, on my server computer (Intel(R) Xeon(R) Gold 6240 CPU @ 2.60GH, 144 core 72 CPU):

reduce from 6min -> 1min

for make ut:

time make ut
building task finish, parallelism=144, count=641, takes=10.154869881s
run all tasks takes 50.559951196s
> make ut  327.15s user 48.61s system 615% cpu 1:01.03 total

for make basic-test

time make basic-test
CGO_ENABLED=1 go test -tags tso_function_test,deadlock -timeout 20m -race
> make basic-test 1176.46s user 169.41s system 473% cpu 5:44.15 total

Check List

Tests

  • Unit test
  • Manual test

Release note

introduce pd-ut to accelerate unit-test

Copy link
Contributor

ti-chi-bot bot commented Mar 20, 2024

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • nolouch
  • rleungx

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

Copy link
Contributor

ti-chi-bot bot commented Mar 20, 2024

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Mar 20, 2024
@ti-chi-bot ti-chi-bot bot requested review from disksing and rleungx March 20, 2024 06:32
pkg/mcs/scheduling/server/rule/watcher_test.go Outdated Show resolved Hide resolved
pkg/slice/slice_test.go Outdated Show resolved Hide resolved
pkg/utils/etcdutil/etcdutil_test.go Outdated Show resolved Hide resolved
pkg/utils/typeutil/size_test.go Outdated Show resolved Hide resolved
}

func (suite *resignTestSuite) TestResignMyself() {
func (suite *memberTestSuite) TestResignMyself() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need to call suite.Clean()?

Signed-off-by: husharp <jinhao.hu@pingcap.com>
@HuSharp HuSharp force-pushed the support_ut branch 2 times, most recently from 532b15b to 5437e68 Compare March 21, 2024 03:39
Copy link

codecov bot commented Mar 21, 2024

Codecov Report

Merging #7952 (c235324) into master (b9240a0) will decrease coverage by 3.64%.
The diff coverage is n/a.

❗ Current head c235324 differs from pull request most recent head 9f93b0e. Consider uploading reports for the commit 9f93b0e to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7952      +/-   ##
==========================================
- Coverage   77.30%   73.66%   -3.64%     
==========================================
  Files         468      436      -32     
  Lines       60879    48525   -12354     
==========================================
- Hits        47061    35748   -11313     
+ Misses      10284     9719     -565     
+ Partials     3534     3058     -476     
Flag Coverage Δ
unittests 73.66% <ø> (-3.64%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@ti-chi-bot ti-chi-bot bot added release-note The PR should write the release note. and removed release-note-none labels Mar 21, 2024

func usage() bool {
msg := `// run all tests
pd-ut
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer to name this as dev, as we can do more scope with dev command , such as

./dev lint
./dev test pkg/util
./dev generator swagger
./dev bench heartbeat

Copy link
Member Author

Choose a reason for hiding this comment

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

maybe can unify all tools in another pr

@HuSharp HuSharp marked this pull request as ready for review March 21, 2024 05:42
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 21, 2024
@HuSharp HuSharp changed the title [DNM] make unit test great tests: make unit test great Mar 21, 2024
@HuSharp HuSharp changed the title tests: make unit test great */unit-test: make unit test great Mar 21, 2024
@HuSharp HuSharp changed the title */unit-test: make unit test great *: make unit test great Mar 21, 2024
Signed-off-by: husharp <jinhao.hu@pingcap.com>
Signed-off-by: husharp <jinhao.hu@pingcap.com>
@@ -225,6 +228,12 @@ failpoint-disable: install-tools

#### Test ####

ut: pd-ut
Copy link
Member

Choose a reason for hiding this comment

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

Do we have a timeout?

Copy link
Member Author

Choose a reason for hiding this comment

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

Signed-off-by: husharp <jinhao.hu@pingcap.com>
@ti-chi-bot ti-chi-bot bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 3, 2024
Signed-off-by: husharp <jinhao.hu@pingcap.com>
@ti-chi-bot ti-chi-bot bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 7, 2024
@ti-chi-bot ti-chi-bot bot added the status/LGT1 Indicates that a PR has LGTM 1. label Apr 9, 2024
@ti-chi-bot ti-chi-bot bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Apr 10, 2024
@HuSharp
Copy link
Member Author

HuSharp commented Apr 10, 2024

/merge

Copy link
Contributor

ti-chi-bot bot commented Apr 10, 2024

@HuSharp: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

Copy link
Contributor

ti-chi-bot bot commented Apr 10, 2024

This pull request has been accepted and is ready to merge.

Commit hash: c235324

@ti-chi-bot ti-chi-bot bot added the status/can-merge Indicates a PR has been approved by a committer. label Apr 10, 2024
Copy link
Contributor

ti-chi-bot bot commented Apr 10, 2024

@HuSharp: Your PR was out of date, I have automatically updated it for you.

If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot ti-chi-bot bot merged commit f0eb74b into tikv:master Apr 10, 2024
22 checks passed
@HuSharp HuSharp deleted the support_ut branch April 10, 2024 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note The PR should write the release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants