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/filesort: migrate test-infra to testify #26946

Closed
wants to merge 1 commit into from

Conversation

kevgeo
Copy link

@kevgeo kevgeo commented Aug 5, 2021

What problem does this PR solve?

Issue Number: close #26178

Problem Summary: refer to #26022

Release note

 None

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has not been approved.

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 the release-note-none Denotes a PR that doesn't merit a release note. label Aug 5, 2021
@ti-chi-bot
Copy link
Member

Welcome @kevgeo!

It looks like this is your first PR to pingcap/tidb 🎉.

I'm the bot to help you request reviewers, add labels and more, See available commands.

We want to make sure your contribution gets all the attention it needs!



Thank you, and welcome to pingcap/tidb. 😃

@ti-chi-bot ti-chi-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 5, 2021
@ti-chi-bot ti-chi-bot requested a review from tisonkun August 5, 2021 20:38
@github-actions github-actions bot added the sig/execution SIG execution label Aug 5, 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.

Thanks for your contribution @kevgeo ! It looks in a good direction. Comments inline.

@@ -0,0 +1,13 @@
package filesort
Copy link
Contributor

Choose a reason for hiding this comment

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

We need a license header here. See other main_test.go file as an example.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for your kind feedback. I will update with the license header.

fsBuilder.SetSchema(keySize, valSize)
_, err = fsBuilder.Build()
c.Assert(err.Error(), Equals, "buffer size is not positive")
require.Equal(t, "buffer size is not positive", err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use EqualError here also.

Copy link
Contributor

Choose a reason for hiding this comment

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

ditto others

Copy link
Author

Choose a reason for hiding this comment

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

EqualError expects the second argument to be of error type and third argument as string.

err.Error() is of string type. So since both second argument i.e "buffer size is not positive" and third argument, err.Error() are of string type, I'm using Equal.

Copy link
Contributor

@tisonkun tisonkun Aug 7, 2021

Choose a reason for hiding this comment

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

If you take a look at how require.EqualError implements, you will found

require.Equal(t, "buffer size is not positive", err.Error())
// equals to
require.EqualError(t, err, "buffer size is not positive")

... with extra check err is not nil so you won't panic and IDE like GoLand won't complain about nil pointer potential.

ret, err := lessThan(sc, t.Arg1, t.Arg2, t.Arg3)
c.Assert(err, IsNil)
c.Assert(ret, Equals, t.Ret)
for _, T := range tblTwoColumns {
Copy link
Contributor

Choose a reason for hiding this comment

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

You may try to name the struct as testCases, iteratee as testCase, for expressive naming.

testCases := []struct {
		datum0 []types.Datum
		datum1 []types.Datum
		byDesc []bool
		res  bool
	}

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, you can join these two cases.

Copy link
Author

Choose a reason for hiding this comment

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

Should I try to differentiate the two different struct testCases by naming the first and second as testCasesTblOneColumn and testCasesTblTwoColumns respectively?

Copy link
Contributor

Choose a reason for hiding this comment

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

You may think of it. My opinion is that they can be the same testCases array.

Preciously, I mean something like

func TestLessThan(t *testing.T) {
	t.Parallel()

	sc := new(stmtctx.StatementContext)

	d0 := types.NewDatum(0)
	d1 := types.NewDatum(1)

	tests := []struct {
		i []types.Datum
		j []types.Datum
		byDesc []bool
		res  bool
	}{
		// one column
		{[]types.Datum{d0}, []types.Datum{d0}, []bool{false}, false},
		{[]types.Datum{d0}, []types.Datum{d1}, []bool{false}, true},
		{[]types.Datum{d1}, []types.Datum{d0}, []bool{false}, false},
		{[]types.Datum{d0}, []types.Datum{d0}, []bool{true}, false},
		{[]types.Datum{d0}, []types.Datum{d1}, []bool{true}, false},
		{[]types.Datum{d1}, []types.Datum{d0}, []bool{true}, true},

		// two columns
		{[]types.Datum{d0, d0}, []types.Datum{d1, d1}, []bool{false, false}, true},
		{[]types.Datum{d0, d1}, []types.Datum{d1, d1}, []bool{false, false}, true},
		{[]types.Datum{d0, d0}, []types.Datum{d1, d1}, []bool{false, false}, true},
		{[]types.Datum{d0, d0}, []types.Datum{d0, d1}, []bool{false, false}, true},
		{[]types.Datum{d0, d1}, []types.Datum{d0, d1}, []bool{false, false}, false},
		{[]types.Datum{d0, d1}, []types.Datum{d0, d0}, []bool{false, false}, false},
		{[]types.Datum{d1, d0}, []types.Datum{d0, d1}, []bool{false, false}, false},
		{[]types.Datum{d1, d1}, []types.Datum{d0, d1}, []bool{false, false}, false},
		{[]types.Datum{d1, d1}, []types.Datum{d0, d0}, []bool{false, false}, false},
	}

	for _, test := range tests {
		res, err := lessThan(sc, test.i, test.j, test.byDesc)
		require.NoError(t, err)
		require.Equal(t, test.res, res)
	}
}

@ti-chi-bot
Copy link
Member

@tisonkun: Request changes is only allowed for the reviewers in list.

In response to this:

Thanks for your contribution @kevgeo ! It looks in a good direction. Comments inline.

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.


fsBuilder := new(Builder)
fs, err = fsBuilder.SetSC(sc).SetSchema(keySize, valSize).SetBuf(bufSize).SetWorkers(1).SetDesc(byDesc).SetDir(tmpDir).Build()
c.Assert(err, IsNil)
require.NoError(t, err)
defer fs.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

try to handle the error by

defer func() {
  err := fs.Close()
  require.NoError(t, err)
}()

@tisonkun
Copy link
Contributor

As @kevgeo inactive for a while, I'll take this PR over.

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. sig/execution SIG execution size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

migrate test-infra to testify for util/filesort pkg
3 participants