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
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tiny change.
  • Loading branch information
hanfei1991 committed Nov 18, 2016
commit af9e2478f3ca513b2805c3291836202b38afc9ae
2 changes: 1 addition & 1 deletion executor/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (m *MockExec) Close() error {
func (s *testSuite) TestAggregation(c *C) {
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.MustExec("drop table if exists t, t1, t2")
defer testleak.AfterTest(c)()
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand Down
4 changes: 2 additions & 2 deletions executor/executor_ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
func (s *testSuite) TestTruncateTable(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec(`drop table if exists truncate_test;`)
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

testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand All @@ -41,7 +41,7 @@ func (s *testSuite) TestTruncateTable(c *C) {
func (s *testSuite) TestCreateTable(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec(`drop table if exists test;`)
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

testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand Down
67 changes: 38 additions & 29 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,20 @@ func (s *testSuite) TearDownSuite(c *C) {
s.store.Close()
}

func (s *testSuite) cleanEnv(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
r := tk.MustQuery("show tables")
for _, tb := range r.Rows() {
tableName := tb[0]
tk.MustExec(fmt.Sprintf("drop table %v", tableName))
}
}

func (s *testSuite) TestAdmin(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists admin_test, admin_test1")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand Down Expand Up @@ -194,7 +204,7 @@ func (s *testSuite) TestSelectWithoutFrom(c *C) {
func (s *testSuite) TestSelectLimit(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists select_limit")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand Down Expand Up @@ -241,7 +251,7 @@ func (s *testSuite) TestSelectLimit(c *C) {
func (s *testSuite) TestSelectOrderBy(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists select_order_test, t")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand Down Expand Up @@ -325,7 +335,7 @@ func (s *testSuite) TestSelectOrderBy(c *C) {
func (s *testSuite) TestSelectDistinct(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists select_distinct_test")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand All @@ -342,7 +352,7 @@ func (s *testSuite) TestSelectDistinct(c *C) {
func (s *testSuite) TestSelectErrorRow(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists test")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand Down Expand Up @@ -379,7 +389,7 @@ func (s *testSuite) TestSelectErrorRow(c *C) {
func (s *testSuite) TestIssue345(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists t1,t2")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand Down Expand Up @@ -423,7 +433,7 @@ func (s *testSuite) TestIssue345(c *C) {
func (s *testSuite) TestUnion(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists union_test")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand Down Expand Up @@ -481,7 +491,7 @@ func (s *testSuite) TestUnion(c *C) {
func (s *testSuite) TestIn(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists t")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand All @@ -501,7 +511,7 @@ func (s *testSuite) TestIn(c *C) {
func (s *testSuite) TestTablePKisHandleScan(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists t")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand Down Expand Up @@ -567,7 +577,7 @@ func (s *testSuite) TestTablePKisHandleScan(c *C) {
func (s *testSuite) TestJoin(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists t, t1, t2, t3")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand Down Expand Up @@ -663,8 +673,7 @@ func (s *testSuite) TestJoin(c *C) {
func (s *testSuite) TestMultiJoin(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists t15,t14,t40,t35,t42,t7,t64,t19,t9,t8,t57")
tk.MustExec("drop table if exists t37,t44,t38,t18,t62,t4,t48,t31,t16,t12")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand Down Expand Up @@ -760,7 +769,7 @@ AND b44=a42`)
func (s *testSuite) TestIndexScan(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists t, tab1")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand Down Expand Up @@ -809,7 +818,7 @@ func (s *testSuite) TestIndexScan(c *C) {
func (s *testSuite) TestSubquerySameTable(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists t")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand All @@ -825,7 +834,7 @@ func (s *testSuite) TestSubquerySameTable(c *C) {
func (s *testSuite) TestIndexReverseOrder(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists t")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand All @@ -847,7 +856,7 @@ func (s *testSuite) TestIndexReverseOrder(c *C) {
func (s *testSuite) TestTableReverseOrder(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists t")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand All @@ -863,7 +872,7 @@ func (s *testSuite) TestTableReverseOrder(c *C) {
func (s *testSuite) TestInSubquery(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists t, t1")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand Down Expand Up @@ -896,7 +905,7 @@ func (s *testSuite) TestInSubquery(c *C) {
func (s *testSuite) TestDefaultNull(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists t")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand All @@ -916,7 +925,7 @@ func (s *testSuite) TestDefaultNull(c *C) {
func (s *testSuite) TestUnsignedPKColumn(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists t")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand All @@ -933,7 +942,7 @@ func (s *testSuite) TestUnsignedPKColumn(c *C) {
func (s *testSuite) TestBuiltin(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists t")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand Down Expand Up @@ -1080,7 +1089,7 @@ func (s *testSuite) TestBuiltin(c *C) {
func (s *testSuite) TestToPBExpr(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists t")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand Down Expand Up @@ -1134,7 +1143,7 @@ func (s *testSuite) TestToPBExpr(c *C) {
func (s *testSuite) TestDatumXAPI(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists t")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand Down Expand Up @@ -1163,7 +1172,7 @@ func (s *testSuite) TestDatumXAPI(c *C) {
func (s *testSuite) TestJoinPanic(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists events")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand All @@ -1175,7 +1184,7 @@ func (s *testSuite) TestJoinPanic(c *C) {
func (s *testSuite) TestSQLMode(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists t")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand Down Expand Up @@ -1212,7 +1221,7 @@ func (s *testSuite) TestSQLMode(c *C) {
func (s *testSuite) TestNewSubquery(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists t, a, b")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand Down Expand Up @@ -1326,7 +1335,7 @@ func (s *testSuite) TestAdapterStatement(c *C) {
func (s *testSuite) TestRow(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists t")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand All @@ -1351,7 +1360,7 @@ func (s *testSuite) TestRow(c *C) {
func (s *testSuite) TestColumnName(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists t")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand Down Expand Up @@ -1384,7 +1393,7 @@ func (s *testSuite) TestColumnName(c *C) {
func (s *testSuite) TestSelectVar(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists t")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand All @@ -1400,7 +1409,7 @@ func (s *testSuite) TestSelectVar(c *C) {
func (s *testSuite) TestHistoryRead(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists history_read")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand Down
24 changes: 11 additions & 13 deletions executor/executor_write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
func (s *testSuite) TestInsert(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists insert_test, insert_test_1, insert_test_2, insert_err")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand Down Expand Up @@ -113,7 +113,7 @@ func (s *testSuite) TestInsert(c *C) {
func (s *testSuite) TestInsertAutoInc(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists insert_autoinc_test")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand Down Expand Up @@ -200,7 +200,7 @@ func (s *testSuite) TestInsertAutoInc(c *C) {
func (s *testSuite) TestInsertIgnore(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists t")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand All @@ -225,8 +225,7 @@ func (s *testSuite) TestInsertIgnore(c *C) {
func (s *testSuite) TestReplace(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists replace_test, replace_test_1, replace_test_2, replace_test_3, replace_test_4, replace_test_5")
tk.MustExec("drop table if exists tIssue989, tIssue1012")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand Down Expand Up @@ -351,7 +350,7 @@ func (s *testSuite) TestReplace(c *C) {
func (s *testSuite) TestUpdate(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists update_test")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand Down Expand Up @@ -423,8 +422,7 @@ func (s *testSuite) fillMultiTableForUpdate(tk *testkit.TestKit) {
func (s *testSuite) TestMultipleTableUpdate(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists items, month")
tk.MustExec("drop table if exists t1, t2")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand Down Expand Up @@ -485,7 +483,7 @@ func (s *testSuite) TestMultipleTableUpdate(c *C) {
func (s *testSuite) TestDelete(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists delete_test")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
s.fillData(tk, "delete_test")
Expand Down Expand Up @@ -535,7 +533,7 @@ func (s *testSuite) fillDataMultiTable(tk *testkit.TestKit) {
func (s *testSuite) TestMultiTableDelete(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists t1, t2, t3")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
s.fillDataMultiTable(tk)
Expand All @@ -551,7 +549,7 @@ func (s *testSuite) TestMultiTableDelete(c *C) {
func (s *testSuite) TestQualifiedDelete(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists t1, t2")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand Down Expand Up @@ -591,7 +589,7 @@ func (s *testSuite) TestQualifiedDelete(c *C) {
func (s *testSuite) TestLoadData(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists load_data_test")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test")
Expand Down Expand Up @@ -773,7 +771,7 @@ func (s *testSuite) TestLoadData(c *C) {
func (s *testSuite) TestLoadDataEscape(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
tk.MustExec("drop table if exists load_data_test")
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk.MustExec("use test; drop table if exists load_data_test;")
Expand Down
Loading