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

statistics: migrate test-infra to testify for sample_test.go #28537

Merged
merged 10 commits into from
Oct 7, 2021

Conversation

feitian124
Copy link
Contributor

What problem does this PR solve?

Issue Number: close #28117

Release note

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Oct 2, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • pingyu
  • tisonkun

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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Oct 2, 2021
@sre-bot
Copy link
Contributor

sre-bot commented Oct 2, 2021

Please follow PR Title Format:

  • pkg [, pkg2, pkg3]: what is changed

Or if the count of mainly changed packages are more than 3, use

  • *: what is changed

After you have format title, you can leave a comment /run-check_title to recheck it

@feitian124 feitian124 changed the title Issue 28117 statistics: migrate test-infra to testify for sample_test.go Oct 2, 2021
@feitian124
Copy link
Contributor Author

/run-check_title

@feitian124
Copy link
Contributor Author

/cc @tisonkun

Comment on lines 221 to 223
if float64(cnt) < expFrequency/(1+delta) || float64(cnt) > expFrequency*(1+delta) {
require.Truef(t, false, "The frequency %v is exceed the Chernoff Bound", cnt)
}
Copy link
Contributor

@pingyu pingyu Oct 4, 2021

Choose a reason for hiding this comment

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

Suggested change
if float64(cnt) < expFrequency/(1+delta) || float64(cnt) > expFrequency*(1+delta) {
require.Truef(t, false, "The frequency %v is exceed the Chernoff Bound", cnt)
}
require.Conditionf(t, func() bool { return float64(cnt) >= expFrequency/(1+delta) && float64(cnt) <= expFrequency*(1+delta) }, "The frequency %v is exceed the Chernoff Bound", cnt)

Copy link
Contributor

Choose a reason for hiding this comment

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

testify has a matcher named InDelta you can make use of.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, updated.
as per https://stackoverflow.com/questions/45310329/difference-between-indelta-and-inepsilon

InDelta receives an absolute value and checks that the difference is less than that value.
InEpsilon receives a % of difference that would be acceptable.

used InEpsilon here.

Comment on lines 266 to 268
if float64(cnt) < expFrequency/(1+delta) || float64(cnt) > expFrequency*(1+delta) {
require.Truef(t, false, "the frequency %v is exceed the Chernoff Bound", cnt)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if float64(cnt) < expFrequency/(1+delta) || float64(cnt) > expFrequency*(1+delta) {
require.Truef(t, false, "the frequency %v is exceed the Chernoff Bound", cnt)
}
require.Conditionf(t, func() bool { return float64(cnt) >= expFrequency/(1+delta) && float64(cnt) <= expFrequency*(1+delta) }, "the frequency %v is exceed the Chernoff Bound", cnt)

Copy link
Contributor

Choose a reason for hiding this comment

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

ditto above.

statistics/sample_serial_test.go Show resolved Hide resolved
statistics/sample_serial_test.go Show resolved Hide resolved
statistics/sample_serial_test.go Outdated Show resolved Hide resolved

func SubTestCollectColumnStats(s *testSampleSuite) func(*testing.T) {
return func(t *testing.T) {
sc := mock.NewContext().GetSessionVars().StmtCtx
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
sc := mock.NewContext().GetSessionVars().StmtCtx
t.Parallel()
sc := mock.NewContext().GetSessionVars().StmtCtx

It seems that all test cases can be paralleled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

after add t.Parallel() tests will fail, you can check, run mulit times.

Copy link
Contributor

Choose a reason for hiding this comment

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

I found that the failure is caused by sharing and iterating testSampleSuite.rs in SubTestCollectColumnStats, SubTestMergeSampleCollector, and SubTestMergeSampleCollector.

I think we can keep these 3 tests in serial, but change the other 3 tests to be parallel, to make test cases as parallel as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, updated.

statistics/sample_serial_test.go Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Oct 5, 2021
}
expFrequency := float64(sampleNum) * float64(loopCnt) / float64(rowNum)
for _, cnt := range itemCnt {
require.InEpsilonf(t, expFrequency, float64(cnt), 0.5, "The frequency %v is exceed the Chernoff Bound", cnt)
Copy link
Contributor

@pingyu pingyu Oct 5, 2021

Choose a reason for hiding this comment

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

It seems that they are not completely equivalent.

InEpsilon(expFrequency, float64(cnt), 0.5) ==>
-0.5 < (float64(cnt) - expFrequency) / expFrequency < 0.5

float64(cnt) > expFrequency/(1+delta) && float64(cnt) < expFrequency*(1+delta) ==>
float64(cnt)/expFrequency > 1/(1+delta) && float64(cnt)/expFrequency < 1+delta ==>
float64(cnt)/expFrequency - 1 > -delta/(1+delta) && float64(cnt)/expFrequency - 1 < delta ==>
-delta/(1+delta) < float64(cnt)/expFrequency - 1 < delta ==>
-delta/(1+delta) < (float64(cnt) - expFrequency)/expFrequency < delta ==>
-0.333 < (float64(cnt) - expFrequency)/expFrequency < 0.5

Copy link
Contributor Author

@feitian124 feitian124 Oct 5, 2021

Choose a reason for hiding this comment

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

yes, you are right.
InEpsilon seems not suitable for this case, the original check actually not bad, reverted.

@ti-chi-bot ti-chi-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 5, 2021
Copy link
Contributor

@pingyu pingyu 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 the status/LGT1 Indicates that a PR has LGTM 1. label Oct 5, 2021
Comment on lines 29 to 33
func TestSample(t *testing.T) {
t.Run("SubTestWeightedSampling", SubTestWeightedSampling())
t.Run("SubTestDistributedWeightedSampling", SubTestDistributedWeightedSampling())
t.Run("SubTestBuildStatsOnRowSample", SubTestBuildStatsOnRowSample())
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@feitian124 you don't have to wrap these tests in TestSample but

func TestWeightedSampling(t *testing.T) {
  t.Parallel()
  ...
}

and so on.

Golang ensures parallel tests only run along with each others.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, updated.
i forgot to refactor after removing the suite dependency.

@ti-chi-bot ti-chi-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Oct 7, 2021
@feitian124
Copy link
Contributor Author

feitian124 commented Oct 7, 2021

ci failed due to #27889

[2021-10-07T03:23:32.292Z] FAIL: db_partition_test.go:2181: testIntegrationSuite5.TestTruncatePartitionAndDropTable
[2021-10-07T03:23:32.292Z] 
[2021-10-07T03:23:32.292Z] db_partition_test.go:2245:
[2021-10-07T03:23:32.292Z]     c.Assert(hasOldPartitionData, IsFalse, Commentf("take time %v", time.Since(startTime)))
[2021-10-07T03:23:32.292Z] ... obtained bool = true
[2021-10-07T03:23:32.292Z] ... take time 15.140463056s

https://ci.pingcap.net/blue/organizations/jenkins/tidb_ghpr_check_2/detail/tidb_ghpr_check_2/36962/pipeline

@feitian124
Copy link
Contributor Author

/run-check_dev_2

@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 Oct 7, 2021
@tisonkun
Copy link
Contributor

tisonkun commented Oct 7, 2021

cc @rebelice @mmyj

Could you help on merging this PR?

@mmyj
Copy link
Member

mmyj commented Oct 7, 2021

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: b39f8d0

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

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

At the same time I will also trigger all tests for you:

/run-all-tests

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 removed the status/can-merge Indicates a PR has been approved by a committer. label Oct 7, 2021
@tisonkun
Copy link
Contributor

tisonkun commented Oct 7, 2021

@Mini256 why the bot cancel merge due to a merge commit?

@mmyj maybe you need to merge again...

@mmyj
Copy link
Member

mmyj commented Oct 7, 2021

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: f877e3f

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Oct 7, 2021
@ti-chi-bot ti-chi-bot merged commit 463cc34 into pingcap:master Oct 7, 2021
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 statistics/sample_test.go
6 participants