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

util/encrypt: migrate test-infra to testify #28016

Merged

Conversation

karuppiah7890
Copy link
Contributor

@karuppiah7890 karuppiah7890 commented Sep 13, 2021

What problem does this PR solve?

Issue Number: close #27816

Problem Summary: migrate test-infra to testify for util/encrypt package

What is changed and how it works?

What's Changed:

Migrated tests to use testify package instead of github.com/pingcap/check package for assertions and any test utils and matchers that github.com/pingcap/check provided

Check List

Tests

  • Unit test

Release note

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Sep 13, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • mmyj
  • morgo

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.

@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Sep 13, 2021
@karuppiah7890
Copy link
Contributor Author

/cc @tisonkun

@ti-chi-bot ti-chi-bot requested a review from tisonkun September 13, 2021 15:34
@karuppiah7890
Copy link
Contributor Author

Question: Do we need the extra options for the goleak? To ignore some top level functions. But I didn't get any leak error while running

{ make failpoint-enable; go test github.com/pingcap/tidb/util/encrypt; make failpoint-disable; }

So I'm guessing there's nothing to ignore in this case, unlike here https://github.com/pingcap/tidb/blob/master/ddl/failtest/main_test.go#L37-L42

@karuppiah7890
Copy link
Contributor Author

By the way, I noticed some unrelated errors while running all the tests -

tidb $ make gotest
Running in native mode.
gsttimeout-check
grep 'PASS:' gotest.log | go run tools/check/check-timeout.go || { $(find $PWD/ -type d | grep -vE "(\.git|tools)" | xargs tools/bin/failpoint-ctl disable); exit 1; }
^R
The following test cases take too long to finish:
PASS: builtin_time_vec_generated_test.go:6727: testVectorizeSuite1.TestVectorizedBuiltinTimeEvalOneVecGenerated	6.754s
PASS: builtin_time_vec_test.go:575: testVectorizeSuite2.TestVectorizedBuiltinTimeEvalOneVec	7.341s
PASS: builtin_time_vec_test.go:579: testVectorizeSuite2.TestVectorizedBuiltinTimeFunc	5.569s
--- PASS: TestClusterConfigInfoschema (5.71s)
--- PASS: TestCTEPreviewAndReport (7.12s)
exit status 252
make: *** [gotest] Error 1
tidb $ 

@karuppiah7890
Copy link
Contributor Author

There seems to be an unrelated error in pipeline too over here https://ci.pingcap.net/blue/organizations/jenkins/tidb_ghpr_check_2/detail/tidb_ghpr_check_2/33109/pipeline

[2021-09-13T15:40:22.324Z] FAIL
[2021-09-13T15:40:22.324Z] + cat test.log
[2021-09-13T15:40:22.324Z] + grep -Ev '^\[[[:digit:]]{4}(/[[:digit:]]{2}){2}'
[2021-09-13T15:40:22.324Z] + grep -A 30 '\-------'
[2021-09-13T15:40:22.324Z] + grep -A 29 FAIL
[2021-09-13T15:40:22.324Z] FAIL: attributes_sql_test.go:237: testDBSuite8.TestFlashbackTable
[2021-09-13T15:40:22.324Z] 
[2021-09-13T15:40:22.324Z] attributes_sql_test.go:301:
[2021-09-13T15:40:22.324Z]     c.Assert(rows2[0][3], Equals, rows[0][3])
[2021-09-13T15:40:22.324Z] ... obtained string = "7480000000000021ff4e5f720000000000fa"
[2021-09-13T15:40:22.324Z] ... expected string = "7480000000000000ff375f720000000000fa"

Signed-off-by: Karuppiah Natarajan <karuppiah7890@users.noreply.github.com>
…7816)

Signed-off-by: Karuppiah Natarajan <karuppiah7890@users.noreply.github.com>
…27816)

Signed-off-by: Karuppiah Natarajan <karuppiah7890@users.noreply.github.com>
pingcap#27816)

Signed-off-by: Karuppiah Natarajan <karuppiah7890@users.noreply.github.com>
pingcap#27816)

Signed-off-by: Karuppiah Natarajan <karuppiah7890@users.noreply.github.com>
pingcap#27816)

Signed-off-by: Karuppiah Natarajan <karuppiah7890@users.noreply.github.com>
pingcap#27816)

Signed-off-by: Karuppiah Natarajan <karuppiah7890@users.noreply.github.com>
pingcap#27816)

Signed-off-by: Karuppiah Natarajan <karuppiah7890@users.noreply.github.com>
pingcap#27816)

Signed-off-by: Karuppiah Natarajan <karuppiah7890@users.noreply.github.com>
pingcap#27816)

Signed-off-by: Karuppiah Natarajan <karuppiah7890@users.noreply.github.com>
pingcap#27816)

Signed-off-by: Karuppiah Natarajan <karuppiah7890@users.noreply.github.com>
…ingcap#27816)

Signed-off-by: Karuppiah Natarajan <karuppiah7890@users.noreply.github.com>
…27816)

Signed-off-by: Karuppiah Natarajan <karuppiah7890@users.noreply.github.com>
…ap#27816)

Signed-off-by: Karuppiah Natarajan <karuppiah7890@users.noreply.github.com>
…ap#27816)

Signed-off-by: Karuppiah Natarajan <karuppiah7890@users.noreply.github.com>
…k suite and golang test

Signed-off-by: Karuppiah Natarajan <karuppiah7890@users.noreply.github.com>
Signed-off-by: Karuppiah Natarajan <karuppiah7890@users.noreply.github.com>
@karuppiah7890 karuppiah7890 force-pushed the migrate-util/encrypt-to-testify branch from 54bcb8d to 5551888 Compare September 13, 2021 15:45
@karuppiah7890
Copy link
Contributor Author

Oops. Sorry, I just did rebase and force pushed and noticed that there was a merge being done

@tisonkun
Copy link
Contributor

Hi @karuppiah7890 ! Thanks for your contribution and sorry for our unstable tests in such a terrible situation.

For any failing tests you found, you can try to find an issue on #25899:

  • If there is already one, report another instance you meet so that we may increase its priority.
  • If there is none, create an issue and ask for link in the tracking issue for unstable tests.

Thanks for your understanding.

@unconsolable
Copy link
Contributor

Question: Do we need the extra options for the goleak? To ignore some top level functions. But I didn't get any leak error while running

{ make failpoint-enable; go test github.com/pingcap/tidb/util/encrypt; make failpoint-disable; }

So I'm guessing there's nothing to ignore in this case, unlike here https://github.com/pingcap/tidb/blob/master/ddl/failtest/main_test.go#L37-L42

For some test cases, goroutine leaks are known issues, we should add these goroutines to ignore list, such as

opts := []goleak.Option{
goleak.IgnoreTopFunction("go.etcd.io/etcd/pkg/logutil.(*MergeLogger).outputLoop"),
goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"),
}

But some goroutine leaks are caused by test code, we should try to fix them.

@tisonkun
Copy link
Contributor

Oops. Sorry, I just did rebase and force pushed and noticed that there was a merge being done

Never mind. If my action causes any inconvenient, please let me know.

In our dev guide it says:

Review and address comments on your pull request. If your pull request becomes outdated with the target branch, you need to rebase your pull request to keep it up to date. Since TiDB uses squash and merge, simply merging master to catch up the change is also acceptable.

Since the catching up so frequently I move to use the merge button gradually.

@karuppiah7890
Copy link
Contributor Author

Makes sense 👍

@tisonkun
Copy link
Contributor

/cc @mmyj @morgo

@ti-chi-bot ti-chi-bot requested review from mmyj and morgo September 13, 2021 15:52
@karuppiah7890
Copy link
Contributor Author

@unconsolable how do I know if my test has any known goroutine leaks and that I need to ignore them? Similar to https://github.com/pingcap/tidb/blob/master/ddl/failtest/main_test.go#L37-L42

How was it found that https://github.com/pingcap/tidb/blob/master/ddl/failtest/main_test.go#L37-L42 has known goroutine leaks - does it always show as leak error or only sometimes?

@unconsolable
Copy link
Contributor

unconsolable commented Sep 13, 2021

@unconsolable how do I know if my test has any known goroutine leaks and that I need to ignore them? Similar to https://github.com/pingcap/tidb/blob/master/ddl/failtest/main_test.go#L37-L42

How was it found that https://github.com/pingcap/tidb/blob/master/ddl/failtest/main_test.go#L37-L42 has known goroutine leaks - does it always show as leak error or only sometimes?

I usually add main_test.go first and run locally, then when I encounter goroutine leak, I will refer the list here

// these go routines are async terminated, so they may still alive after test end, thus cause
// false positive leak failures
"google.golang.org/grpc.(*addrConn).resetTransport",
"google.golang.org/grpc.(*ccBalancerWrapper).watcher",
"github.com/pingcap/goleveldb/leveldb/util.(*BufferPool).drain",
"github.com/pingcap/goleveldb/leveldb.(*DB).compactionError",
"github.com/pingcap/goleveldb/leveldb.(*DB).mpoolDrain",
"go.etcd.io/etcd/pkg/logutil.(*MergeLogger).outputLoop",
"go.etcd.io/etcd/v3/pkg/logutil.(*MergeLogger).outputLoop",
"oracles.(*pdOracle).updateTS",
"tikv.(*KVStore).runSafePointChecker",
"tikv.(*RegionCache).asyncCheckAndResolveLoop",
"github.com/pingcap/badger",
"github.com/ngaut/unistore/tikv.(*MVCCStore).runUpdateSafePointLoop",
"github.com/tikv/client-go/v2/tikv.(*ttlManager).keepAlive", // See https://github.com/tikv/client-go/issues/174

However, there is a exception. #27704 (comment)

Solution

callback := func(i int) int {
// wait for leveldb to close, leveldb will be closed in one second
time.Sleep(time.Second)
return i
}
goleak.VerifyTestMain(testmain.WrapTestingM(m, callback), opts...)

@karuppiah7890
Copy link
Contributor Author

Cool ! So, when I ran in my local, I noticed no issues / errors related to goroutine leaks, let me also check the exception now

@karuppiah7890
Copy link
Contributor Author

Looks like after rebase there are no unstable errors in my local and in CI, interesting

@tisonkun
Copy link
Contributor

@karuppiah7890 the most unstable timeout checker is temporarily disabled by #27980

@karuppiah7890
Copy link
Contributor Author

Ah okay!

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Sep 13, 2021
Copy link
Member

@mmyj mmyj left a comment

Choose a reason for hiding this comment

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

lgtm

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Sep 14, 2021
@mmyj
Copy link
Member

mmyj commented Sep 14, 2021

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 5551888

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

@tisonkun tisonkun left a comment

Choose a reason for hiding this comment

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

@karuppiah7890 I think almost these test cases can be run in parallel.

@ti-chi-bot ti-chi-bot merged commit 406ffe7 into pingcap:master Sep 14, 2021
@karuppiah7890
Copy link
Contributor Author

@tisonkun I just saw this comment. Should I raise another PR? With t.Parallel() in all these tests. That's what you mean right @tisonkun ?

@tisonkun
Copy link
Contributor

tisonkun commented Sep 14, 2021

@tisonkun I just saw this comment. Should I raise another PR? With t.Parallel() in all these tests. That's what you mean right @tisonkun ?

I think it is ok to leave as is since it is almost lightweight test. But if you can investigate the possibility for running in parallel, I'm glad to give it a review and moderate the contribution. You can create an issue for the follow up and then a PR, if you'd like to do it.

@karuppiah7890
Copy link
Contributor Author

Yes, the tests are lightweight indeed, all running within less than 1 second. But yes, parallelization would be cool. I will raise an issue and a PR for it sometime 👍

@karuppiah7890
Copy link
Contributor Author

Created the issue for now - #28034

@karuppiah7890 karuppiah7890 deleted the migrate-util/encrypt-to-testify branch September 14, 2021 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 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.

migrate test-infra to testify for util/encrypt pkg
6 participants