-
Notifications
You must be signed in to change notification settings - Fork 3.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
roachtest: UT for test selection #130079
roachtest: UT for test selection #130079
Conversation
2c9a239
to
e26b555
Compare
b3e692e
to
1c05103
Compare
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 haven't taken a deep look at this PR yet, but wrt #130330, it's good that it caught that bug, but the fact it was just an occasional flake makes me think we should add a bit more. We should have all the parts to do a full simulation (in addition to these hard coded edge cases).
i.e. generate some random starting state, run test selection, randomly pass/fail/preempt some tests, mock writing back the data, then repeat over N days. You can then check invariants at each step, i.e. preempted test is selected the next day, all tests have been run in last 4 days, etc.
Wdyt? Could also be a followup, since it might be a non trivial amount of code.
1c05103
to
83d0236
Compare
The current tests covers all known scenarios. But, randomised test is a good idea to generate Fuzzy kind of test cases - I will check how this can be achieved. |
@DarrylWong randomised test is making it complex for the assertion, but it should be doable. But, I am thinking of raising another PR later for that. Please do let me know if that sound ok to you. |
83d0236
to
93a0ee3
Compare
pkg/cmd/roachtest/main_test.go
Outdated
testselector.SqlConnectorFunc = func(_, _ string) (*gosql.DB, error) { | ||
return db, err | ||
} | ||
t.Run("expect CategoriseTests to fail", func(t *testing.T) { |
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.
From my understanding we aren't testing to see if CategoriseTests
will fail, but rather that if it does we should expect the test selector to fall back to all tests selected. Could we make that more clear through the test name + comments?
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 will change the test name to "expect CategoriseTests to fail which causes fall back to run all tests". Also, will add comment.
for _, s := range specs { | ||
s.Suites = registry.Suites(registry.Nightly, registry.Weekly) | ||
} | ||
data := [][]string{ |
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.
For those less familiar with the snowflake query, can you leave a comment explaining what the four fields are below?
pkg/cmd/roachtest/main_test.go
Outdated
// all tests which contains "_randomized" are set in spec as Randomized=true | ||
func getMockData() ([]registry.TestSpec, *sqlmock.Rows) { | ||
specs := []registry.TestSpec{ | ||
{Name: "t2_selected"}, |
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.
nit: what's the naming convention of these test names? 😅 Some have a number after t, some have it at the end of the name, some don't have a number, some are out of order. If there's a reason to not make it standardized lets add a comment.
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.
Sure, I will add a comments. The entries have been manually shuffled around and the some names were added later, so, is the mismatch in names.
// all tests which contains "new_test" are present in specs, but missing in snowflake rows | ||
// all tests which contains "_randomized" are set in spec as Randomized=true | ||
func getMockData() ([]registry.TestSpec, *sqlmock.Rows) { | ||
specs := []registry.TestSpec{ |
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.
Can we leave comments explaining what case we are actually testing for? i.e. for t_new_test_3
we expect that it's still selected as there's no data in snowflake even though it is not part of the 30% selection rate.
93a0ee3
to
a6be180
Compare
Thanks @DarrylWong for your review. I have addressed the comments. Please do take a look. |
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.
This mostly looks good to me. My remaining comments are mostly just noting that some tests seem redundant to me.
t.Run("expect Prepare to fail", func(t *testing.T) { | ||
db, mock, err = sqlmock.New() | ||
require.Nil(t, err) | ||
mock.ExpectPrepare(regexp.QuoteMeta(PreparedQuery)).WillReturnError(fmt.Errorf("failed to prepare")) |
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.
This seems like it's testing the sql mock more than it is the CategoriseTests
. No harm in keeping it but I feel like expect CategoriseTests to fail which causes fall back to run all tests
test above already covers this case.
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.
This is to test that we are returning the error correctly from the code.
require.Equal(t, defaultLastRunOn, req.LastRunOn) | ||
} | ||
|
||
func Test_getSFCreds(t *testing.T) { |
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.
Similar comment to above, these tests seem to be already covered by TestCategoriseTests
? Not sure how much extra coverage we get.
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.
This is for the coverage of all error scenarios and ensure that we are returning the errors.
a6be180
to
786f5eb
Compare
Thanks @DarrylWong ! I have replied to your comments. Please do let me know if it sounds good. |
786f5eb
to
147ac90
Compare
This PR has the unit tests for the test selection changes. The tests the selector and the main code. This does not validate the snowflake query, but, simulates the response for other tests. Fixes: cockroachdb#129786 Epic: None
147ac90
to
fce0b2d
Compare
Thanks @DarrylWong for reviewing this. |
bors r=@DarrylWong |
This PR has the unit tests for the test selection changes. The tests the selector and the main code. This does not validate the snowflake query, but, simulates the response for other tests.
With this change, we have a coverage of 96% for the test selection.
Fixes: #129786
Epic: None