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

executor_test: clean enviroment for each test. #2025

Merged
merged 8 commits into from
Nov 18, 2016
Merged

Conversation

hanfei1991
Copy link
Member

@hanfei1991 hanfei1991 commented Nov 17, 2016

We should clean the evironment for every test, so as to avoid one test can use a table that created by another test.
@shenli @coocood @ngaut @XuHuaiyu @zimulala PTAL

@@ -132,6 +132,8 @@ func (s *testSuite) TestAdmin(c *C) {
c.Assert(err, IsNil)
r, err = tk.Exec("admin check table admin_test")
c.Assert(err, NotNil)
tk.MustExec("drop table admin_test")
tk.MustExec("drop table admin_test1")
Copy link
Member

Choose a reason for hiding this comment

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

Can be written in one statement.

@@ -259,6 +259,7 @@ func (s *testSuite) TestAggregation(c *C) {
tk.MustExec("insert into t2 values(22, 2), (3, 12), (38, 98)")
result = tk.MustQuery("SELECT COALESCE ( + 1, cor0.col0 ) + - CAST( NULL AS DECIMAL ) FROM t2, t1 AS cor0, t2 AS cor1 GROUP BY cor0.col1")
result.Check(testkit.Rows("<nil>", "<nil>"))
tk.MustExec("drop table t, t1, t2")
Copy link
Member

Choose a reason for hiding this comment

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

Could you use defer statement?

Copy link
Member Author

Choose a reason for hiding this comment

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

any benifit of using defer?

Copy link
Member

Choose a reason for hiding this comment

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

Clean, and you will never forget to clean up table.

@hanfei1991
Copy link
Member Author

@ngaut PTAL

tk := testkit.NewTestKit(c, s.store)
defer func() {
testleak.AfterTest(c)()
tk.MustExec("drop table if exists t, t1, t2")
Copy link
Member

Choose a reason for hiding this comment

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

This should be executed before testleak.AfterTest(c)()

tk := testkit.NewTestKit(c, s.store)
defer func() {
testleak.AfterTest(c)()
tk.MustExec("drop table if exists t15")
Copy link
Contributor

Choose a reason for hiding this comment

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

These statements can be synthesized into a statement.

@coocood
Copy link
Member

coocood commented Nov 17, 2016

Usually we call defer right after resource is created, in this case, the pattern would be.

tk.MustExec("create table t (a int)")
defer tk.MustExec("drop table if exists t")

So it's very easy to check that resource has been cleaned up.

@zimulala
Copy link
Contributor

LGTM

@shenli
Copy link
Member

shenli commented Nov 17, 2016

@hanfei1991 Please add description for the PR.

@hanfei1991
Copy link
Member Author

@ngaut @coocood PTAL

tk := testkit.NewTestKit(c, s.store)
defer func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't understand this change

tk := testkit.NewTestKit(c, s.store)
defer func() {
defer testleak.AfterTest(c)()
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

tk := testkit.NewTestKit(c, s.store)
defer func() {
defer testleak.AfterTest(c)()
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

rest LGTM

@tiancaiamao
Copy link
Contributor

LGTM

There is one concern that if we want run unit test parallel, cleanEnv would make trouble.
PTAL @coocood

@coocood
Copy link
Member

coocood commented Nov 18, 2016

LGTM

@hanfei1991 hanfei1991 merged commit 39a2c09 into master Nov 18, 2016
@hanfei1991 hanfei1991 deleted the hanfei/clean branch November 18, 2016 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants