-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
30ee479
executor_test: clean enviroment for each test.
hanfei1991 650db7c
use defer stmt
hanfei1991 08ab30e
adjust stmt order.
hanfei1991 6f055ca
shorten code.
hanfei1991 af9e247
tiny change.
hanfei1991 0cb724b
tiny change.
hanfei1991 f60e775
tiny change.
hanfei1991 44d18d2
Merge branch 'master' into hanfei/clean
ngaut File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be written in one statement. |
||
} | ||
|
||
func (s *testSuite) fillData(tk *testkit.TestKit, table string) { | ||
|
@@ -311,6 +313,7 @@ func (s *testSuite) TestSelectOrderBy(c *C) { | |
r.Check(testkit.Rows("0", "-1", "-2")) | ||
r = tk.MustQuery("select t.d from t order by d;") | ||
r.Check(testkit.Rows("1", "2", "3")) | ||
tk.MustExec("drop table t") | ||
} | ||
|
||
func (s *testSuite) TestSelectDistinct(c *C) { | ||
|
@@ -401,6 +404,7 @@ func (s *testSuite) TestIssue345(c *C) { | |
c.Assert(err, NotNil) | ||
|
||
tk.MustExec("commit") | ||
tk.MustExec(`drop table t1, t2`) | ||
} | ||
|
||
func (s *testSuite) TestUnion(c *C) { | ||
|
@@ -456,6 +460,7 @@ func (s *testSuite) TestUnion(c *C) { | |
r.Check(testkit.Rows("abc", "1")) | ||
|
||
tk.MustExec("commit") | ||
tk.MustExec("drop table union_test") | ||
} | ||
|
||
func (s *testSuite) TestIn(c *C) { | ||
|
@@ -473,6 +478,7 @@ func (s *testSuite) TestIn(c *C) { | |
|
||
queryStr = `select c2 from t where c1 in ('7a')` | ||
tk.MustQuery(queryStr).Check(testkit.Rows("7")) | ||
tk.MustExec(`drop table t`) | ||
} | ||
|
||
func (s *testSuite) TestTablePKisHandleScan(c *C) { | ||
|
@@ -536,6 +542,7 @@ func (s *testSuite) TestTablePKisHandleScan(c *C) { | |
result := tk.MustQuery(ca.sql) | ||
result.Check(ca.result) | ||
} | ||
tk.MustExec(`drop table t`) | ||
} | ||
|
||
func (s *testSuite) TestJoin(c *C) { | ||
|
@@ -628,14 +635,17 @@ func (s *testSuite) TestJoin(c *C) { | |
_, err = tk.Exec("select * from t right join t1 on 1") | ||
c.Check(plan.ErrCartesianProductUnsupported.Equal(err), IsTrue) | ||
plan.AllowCartesianProduct = true | ||
tk.MustExec("drop table t") | ||
tk.MustExec("drop table t1") | ||
tk.MustExec("drop table t2") | ||
tk.MustExec("drop table t3") | ||
|
||
} | ||
|
||
func (s *testSuite) TestMultiJoin(c *C) { | ||
defer testleak.AfterTest(c)() | ||
tk := testkit.NewTestKit(c, s.store) | ||
tk.MustExec("use test") | ||
tk.MustExec("drop table if exists t") | ||
tk.MustExec("create table t35(a35 int primary key, b35 int, x35 int)") | ||
tk.MustExec("create table t40(a40 int primary key, b40 int, x40 int)") | ||
tk.MustExec("create table t14(a14 int primary key, b14 int, x14 int)") | ||
|
@@ -723,6 +733,27 @@ AND a62=b18 | |
AND b4=a37 | ||
AND b44=a42`) | ||
result.Check(testkit.Rows("7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7")) | ||
tk.MustExec("drop table t15") | ||
tk.MustExec("drop table t14") | ||
tk.MustExec("drop table t40") | ||
tk.MustExec("drop table t35") | ||
tk.MustExec("drop table t42") | ||
tk.MustExec("drop table t7") | ||
tk.MustExec("drop table t64") | ||
tk.MustExec("drop table t19") | ||
tk.MustExec("drop table t9") | ||
tk.MustExec("drop table t8") | ||
tk.MustExec("drop table t57") | ||
tk.MustExec("drop table t37") | ||
tk.MustExec("drop table t44") | ||
tk.MustExec("drop table t38") | ||
tk.MustExec("drop table t18") | ||
tk.MustExec("drop table t62") | ||
tk.MustExec("drop table t4") | ||
tk.MustExec("drop table t48") | ||
tk.MustExec("drop table t31") | ||
tk.MustExec("drop table t16") | ||
tk.MustExec("drop table t12") | ||
} | ||
|
||
func (s *testSuite) TestIndexScan(c *C) { | ||
|
@@ -769,6 +800,8 @@ func (s *testSuite) TestIndexScan(c *C) { | |
tk.MustExec("INSERT INTO tab1 VALUES(1,37,20.85,30,10.69)") | ||
result = tk.MustQuery("SELECT pk FROM tab1 WHERE ((col3 <= 6 OR col3 < 29 AND (col0 < 41)) OR col3 > 42) AND col1 >= 96.1 AND col3 = 30 AND col3 > 17 AND (col0 BETWEEN 36 AND 42)") | ||
result.Check(testkit.Rows()) | ||
tk.MustExec("drop table t") | ||
tk.MustExec("drop table tab1") | ||
} | ||
|
||
func (s *testSuite) TestSubquerySameTable(c *C) { | ||
|
@@ -782,6 +815,7 @@ func (s *testSuite) TestSubquerySameTable(c *C) { | |
result.Check(testkit.Rows("2")) | ||
result = tk.MustQuery("select a from t where not exists(select 1 from t as x where x.a < t.a)") | ||
result.Check(testkit.Rows("1")) | ||
tk.MustExec("drop table t") | ||
} | ||
|
||
func (s *testSuite) TestIndexReverseOrder(c *C) { | ||
|
@@ -801,6 +835,7 @@ func (s *testSuite) TestIndexReverseOrder(c *C) { | |
tk.MustExec("insert t values (0, 2), (1, 2), (2, 2), (0, 1), (1, 1), (2, 1), (0, 0), (1, 0), (2, 0)") | ||
result = tk.MustQuery("select b, a from t order by b, a desc") | ||
result.Check(testkit.Rows("0 2", "0 1", "0 0", "1 2", "1 1", "1 0", "2 2", "2 1", "2 0")) | ||
tk.MustExec("drop table t") | ||
} | ||
|
||
func (s *testSuite) TestTableReverseOrder(c *C) { | ||
|
@@ -814,6 +849,7 @@ func (s *testSuite) TestTableReverseOrder(c *C) { | |
result.Check(testkit.Rows("9", "8", "7", "6", "5", "4", "3", "2", "1")) | ||
result = tk.MustQuery("select a from t where a <3 or (a >=6 and a < 8) order by a desc") | ||
result.Check(testkit.Rows("7", "6", "2", "1")) | ||
tk.MustExec("drop table t") | ||
} | ||
|
||
func (s *testSuite) TestInSubquery(c *C) { | ||
|
@@ -844,6 +880,8 @@ func (s *testSuite) TestInSubquery(c *C) { | |
tk.MustExec("create table t1 (a float)") | ||
tk.MustExec("insert t1 values (281.37)") | ||
tk.MustQuery("select a from t1 where (a in (select a from t1))").Check(testkit.Rows("281.37")) | ||
tk.MustExec("drop table t") | ||
tk.MustExec("drop table t1") | ||
} | ||
|
||
func (s *testSuite) TestDefaultNull(c *C) { | ||
|
@@ -861,6 +899,7 @@ func (s *testSuite) TestDefaultNull(c *C) { | |
tk.MustExec("delete from t where a = 1") | ||
tk.MustExec("insert t (a) values (1)") | ||
tk.MustQuery("select * from t").Check(testkit.Rows("1 1 <nil>")) | ||
tk.MustExec("drop table t") | ||
} | ||
|
||
func (s *testSuite) TestUnsignedPKColumn(c *C) { | ||
|
@@ -875,6 +914,7 @@ func (s *testSuite) TestUnsignedPKColumn(c *C) { | |
tk.MustExec("update t set c=2 where a=1;") | ||
result = tk.MustQuery("select * from t where b=1;") | ||
result.Check(testkit.Rows("1 1 2")) | ||
tk.MustExec("drop table t") | ||
} | ||
|
||
func (s *testSuite) TestBuiltin(c *C) { | ||
|
@@ -1019,6 +1059,7 @@ func (s *testSuite) TestBuiltin(c *C) { | |
{".*", "abcd", 1}, | ||
} | ||
patternMatching(c, tk, "regexp", testCases) | ||
tk.MustExec("drop table t") | ||
} | ||
|
||
func (s *testSuite) TestToPBExpr(c *C) { | ||
|
@@ -1071,6 +1112,7 @@ func (s *testSuite) TestToPBExpr(c *C) { | |
result.Check(testkit.Rows("1")) | ||
result = tk.MustQuery("select * from t where not(a != 1 and a != 2)") | ||
result.Check(testkit.Rows("1", "2")) | ||
tk.MustExec("drop table t") | ||
} | ||
|
||
func (s *testSuite) TestDatumXAPI(c *C) { | ||
|
@@ -1097,6 +1139,7 @@ func (s *testSuite) TestDatumXAPI(c *C) { | |
result.Check(testkit.Rows("11:11:12 11:11:12", "11:11:13 11:11:13")) | ||
result = tk.MustQuery("select * from t where b > '11:11:11.5'") | ||
result.Check(testkit.Rows("11:11:12 11:11:12", "11:11:13 11:11:13")) | ||
tk.MustExec("drop table t") | ||
} | ||
|
||
func (s *testSuite) TestJoinPanic(c *C) { | ||
|
@@ -1106,6 +1149,7 @@ func (s *testSuite) TestJoinPanic(c *C) { | |
tk.MustExec("drop table if exists events") | ||
tk.MustExec("create table events (clock int, source int)") | ||
tk.MustQuery("SELECT * FROM events e JOIN (SELECT MAX(clock) AS clock FROM events e2 GROUP BY e2.source) e3 ON e3.clock=e.clock") | ||
tk.MustExec("drop table events") | ||
} | ||
|
||
func (s *testSuite) TestSQLMode(c *C) { | ||
|
@@ -1140,6 +1184,7 @@ func (s *testSuite) TestSQLMode(c *C) { | |
c.Check(err, NotNil) | ||
// Restore original global strict mode. | ||
tk.MustExec("set @@global.sql_mode = 'STRICT_TRANS_TABLES'") | ||
tk.MustExec("drop table t") | ||
} | ||
|
||
func (s *testSuite) TestNewSubquery(c *C) { | ||
|
@@ -1198,6 +1243,9 @@ func (s *testSuite) TestNewSubquery(c *C) { | |
|
||
result = tk.MustQuery("select * from a b where c = (select d from b a where a.c = 2 and b.c = 1)") | ||
result.Check(testkit.Rows("1 2")) | ||
tk.MustExec("drop table t") | ||
tk.MustExec("drop table a") | ||
tk.MustExec("drop table b") | ||
} | ||
|
||
func (s *testSuite) TestNewTableDual(c *C) { | ||
|
@@ -1273,6 +1321,7 @@ func (s *testSuite) TestRow(c *C) { | |
result.Check(testkit.Rows("1 1")) | ||
result = tk.MustQuery("select * from t where (c, d) = (select * from t k where (t.c,t.d) = (c,d))") | ||
result.Check(testkit.Rows("1 1", "1 3", "2 1", "2 3")) | ||
tk.MustExec("drop table t") | ||
} | ||
|
||
func (s *testSuite) TestColumnName(c *C) { | ||
|
@@ -1302,6 +1351,7 @@ func (s *testSuite) TestColumnName(c *C) { | |
c.Check(len(fields), Equals, 2) | ||
c.Check(fields[0].Column.Name.L, Equals, "d") | ||
c.Check(fields[1].Column.Name.L, Equals, "c") | ||
tk.MustExec("drop table t") | ||
} | ||
|
||
func (s *testSuite) TestSelectVar(c *C) { | ||
|
@@ -1314,6 +1364,7 @@ func (s *testSuite) TestSelectVar(c *C) { | |
result.Check(testkit.Rows("<nil> 2", "<nil> 3", "<nil> 2")) | ||
result = tk.MustQuery("select @a, @a := d+1 from t") | ||
result.Check(testkit.Rows("2 2", "2 3", "3 2")) | ||
tk.MustExec("drop table t") | ||
|
||
} | ||
|
||
|
@@ -1359,4 +1410,5 @@ func (s *testSuite) TestHistoryRead(c *C) { | |
tk.MustQuery("select * from history_read order by a").Check(testkit.Rows("2", "4")) | ||
tk.MustExec("set @@tidb_snapshot = ''") | ||
tk.MustQuery("select * from history_read order by a").Check(testkit.Rows("2 <nil>", "4 <nil>", "8 8", "9 9")) | ||
tk.MustExec("drop table history_read") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could you use defer statement?
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.
any benifit of using defer?
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.
Clean, and you will never forget to clean up table.