-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Conversation
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
Please follow PR Title Format:
Or if the count of mainly changed packages are more than 3, use
After you have format title, you can leave a comment |
/run-check_title |
/cc @tisonkun |
statistics/sample_serial_test.go
Outdated
if float64(cnt) < expFrequency/(1+delta) || float64(cnt) > expFrequency*(1+delta) { | ||
require.Truef(t, false, "The frequency %v is exceed the Chernoff Bound", cnt) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
statistics/sample_serial_test.go
Outdated
if float64(cnt) < expFrequency/(1+delta) || float64(cnt) > expFrequency*(1+delta) { | ||
require.Truef(t, false, "the frequency %v is exceed the Chernoff Bound", cnt) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto above.
|
||
func SubTestCollectColumnStats(s *testSampleSuite) func(*testing.T) { | ||
return func(t *testing.T) { | ||
sc := mock.NewContext().GetSessionVars().StmtCtx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sc := mock.NewContext().GetSessionVars().StmtCtx | |
t.Parallel() | |
sc := mock.NewContext().GetSessionVars().StmtCtx |
It seems that all test cases can be paralleled.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, updated.
Co-authored-by: Ping Yu <shuiyu.cn@gmail.com>
Co-authored-by: Ping Yu <shuiyu.cn@gmail.com>
992d8af
to
3995d76
Compare
statistics/sample_test.go
Outdated
} | ||
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
This reverts commit 96bf2ea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
statistics/sample_test.go
Outdated
func TestSample(t *testing.T) { | ||
t.Run("SubTestWeightedSampling", SubTestWeightedSampling()) | ||
t.Run("SubTestDistributedWeightedSampling", SubTestDistributedWeightedSampling()) | ||
t.Run("SubTestBuildStatsOnRowSample", SubTestBuildStatsOnRowSample()) | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
ci failed due to #27889
|
/run-check_dev_2 |
/merge |
This pull request has been accepted and is ready to merge. Commit hash: b39f8d0
|
@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. |
/merge |
This pull request has been accepted and is ready to merge. Commit hash: f877e3f
|
What problem does this PR solve?
Issue Number: close #28117
Release note