Skip to content

Commit

Permalink
ddl,expression: make leak test more stable (#4895)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored and coocood committed Oct 25, 2017
1 parent 6a8fd11 commit 834d51f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 94 deletions.
3 changes: 2 additions & 1 deletion ddl/foreign_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ type testForeighKeySuite struct {
}

func (s *testForeighKeySuite) SetUpSuite(c *C) {
testleak.BeforeTest()
s.store = testCreateStore(c, "test_foreign")
}

func (s *testForeighKeySuite) TearDownSuite(c *C) {
err := s.store.Close()
c.Assert(err, IsNil)
testleak.AfterTest(c)()
}

func (s *testForeighKeySuite) testCreateForeignKey(c *C, tblInfo *model.TableInfo, fkName string, keys []string, refTable string, refKeys []string, onDelete ast.ReferOptionType, onUpdate ast.ReferOptionType) *model.Job {
Expand Down Expand Up @@ -110,7 +112,6 @@ func getForeignKey(t table.Table, name string) *model.FKInfo {
}

func (s *testForeighKeySuite) TestForeignKey(c *C) {
defer testleak.AfterTest(c)()
d := testNewDDL(goctx.Background(), nil, s.store, nil, nil, testLease)
defer d.Stop()
s.d = d
Expand Down
117 changes: 24 additions & 93 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func (s *testIntegrationSuite) cleanEnv(c *C) {

func (s *testIntegrationSuite) SetUpSuite(c *C) {
var err error
testleak.BeforeTest()
s.store, s.dom, err = newStoreWithBootstrap()
c.Assert(err, IsNil)
s.ctx = mock.NewContext()
Expand All @@ -67,14 +68,12 @@ func (s *testIntegrationSuite) SetUpSuite(c *C) {
func (s *testIntegrationSuite) TearDownSuite(c *C) {
s.dom.Close()
s.store.Close()
testleak.AfterTest(c)()
}

func (s *testIntegrationSuite) TestFuncREPEAT(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
defer s.cleanEnv(c)
tk.MustExec("USE test;")
tk.MustExec("DROP TABLE IF EXISTS table_string;")
tk.MustExec("CREATE TABLE table_string(a CHAR(20), b VARCHAR(20), c TINYTEXT, d TEXT(20), e MEDIUMTEXT, f LONGTEXT, g BIGINT);")
Expand Down Expand Up @@ -108,10 +107,7 @@ func (s *testIntegrationSuite) TestFuncREPEAT(c *C) {

func (s *testIntegrationSuite) TestFuncLpadAndRpad(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
defer s.cleanEnv(c)
tk.MustExec(`USE test;`)
tk.MustExec(`DROP TABLE IF EXISTS t;`)
tk.MustExec(`CREATE TABLE t(a BINARY(10), b CHAR(10));`)
Expand All @@ -131,10 +127,7 @@ func (s *testIntegrationSuite) TestFuncLpadAndRpad(c *C) {
}

func (s *testIntegrationSuite) TestMiscellaneousBuiltin(c *C) {
defer func() {
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
defer s.cleanEnv(c)

tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down Expand Up @@ -213,10 +206,7 @@ func (s *testIntegrationSuite) TestMiscellaneousBuiltin(c *C) {
}

func (s *testIntegrationSuite) TestConvertToBit(c *C) {
defer func() {
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
defer s.cleanEnv(c)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t, t1")
Expand All @@ -242,10 +232,7 @@ func (s *testIntegrationSuite) TestConvertToBit(c *C) {
}

func (s *testIntegrationSuite) TestMathBuiltin(c *C) {
defer func() {
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
defer s.cleanEnv(c)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")

Expand Down Expand Up @@ -531,10 +518,7 @@ func (s *testIntegrationSuite) TestMathBuiltin(c *C) {
}

func (s *testIntegrationSuite) TestStringBuiltin(c *C) {
defer func() {
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
defer s.cleanEnv(c)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")

Expand Down Expand Up @@ -896,10 +880,7 @@ func (s *testIntegrationSuite) TestStringBuiltin(c *C) {
}

func (s *testIntegrationSuite) TestEncryptionBuiltin(c *C) {
defer func() {
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
defer s.cleanEnv(c)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")

Expand Down Expand Up @@ -1022,7 +1003,6 @@ func (s *testIntegrationSuite) TestTimeBuiltin(c *C) {
defer func() {
s.ctx.GetSessionVars().StrictSQLMode = originSQLMode
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down Expand Up @@ -1706,10 +1686,7 @@ func (s *testIntegrationSuite) TestTimeBuiltin(c *C) {
}

func (s *testIntegrationSuite) TestOpBuiltin(c *C) {
defer func() {
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
defer s.cleanEnv(c)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")

Expand Down Expand Up @@ -1749,10 +1726,7 @@ func (s *testIntegrationSuite) TestOpBuiltin(c *C) {
}

func (s *testIntegrationSuite) TestBuiltin(c *C) {
defer func() {
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
defer s.cleanEnv(c)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")

Expand Down Expand Up @@ -2120,10 +2094,7 @@ func (s *testIntegrationSuite) TestBuiltin(c *C) {
}

func (s *testIntegrationSuite) TestInfoBuiltin(c *C) {
defer func() {
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
defer s.cleanEnv(c)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")

Expand Down Expand Up @@ -2209,10 +2180,7 @@ func (s *testIntegrationSuite) TestInfoBuiltin(c *C) {
}

func (s *testIntegrationSuite) TestControlBuiltin(c *C) {
defer func() {
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
defer s.cleanEnv(c)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")

Expand Down Expand Up @@ -2271,10 +2239,7 @@ func (s *testIntegrationSuite) TestControlBuiltin(c *C) {
}

func (s *testIntegrationSuite) TestArithmeticBuiltin(c *C) {
defer func() {
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
defer s.cleanEnv(c)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")

Expand Down Expand Up @@ -2444,10 +2409,7 @@ func (s *testIntegrationSuite) TestArithmeticBuiltin(c *C) {
}

func (s *testIntegrationSuite) TestCompareBuiltin(c *C) {
defer func() {
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
defer s.cleanEnv(c)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")

Expand Down Expand Up @@ -2607,10 +2569,7 @@ func (s *testIntegrationSuite) TestCompareBuiltin(c *C) {
}

func (s *testIntegrationSuite) TestAggregationBuiltin(c *C) {
defer func() {
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
defer s.cleanEnv(c)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("create table t(a decimal(7, 6))")
Expand All @@ -2620,10 +2579,7 @@ func (s *testIntegrationSuite) TestAggregationBuiltin(c *C) {
}

func (s *testIntegrationSuite) TestOtherBuiltin(c *C) {
defer func() {
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
defer s.cleanEnv(c)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")

Expand Down Expand Up @@ -2681,11 +2637,7 @@ func (s *testIntegrationSuite) TestOtherBuiltin(c *C) {
}

func (s *testIntegrationSuite) TestDateBuiltin(c *C) {
defer func() {
s.cleanEnv(c)
testleak.AfterTest(c)()
}()

defer s.cleanEnv(c)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("USE test;")
tk.MustExec("DROP TABLE IF EXISTS t;")
Expand Down Expand Up @@ -2772,11 +2724,7 @@ func (s *testIntegrationSuite) TestDateBuiltin(c *C) {
}

func (s *testIntegrationSuite) TestTimeLiteral(c *C) {
defer func() {
s.cleanEnv(c)
testleak.AfterTest(c)()
}()

defer s.cleanEnv(c)
tk := testkit.NewTestKit(c, s.store)

r := tk.MustQuery("select time '117:01:12';")
Expand Down Expand Up @@ -2820,11 +2768,7 @@ func (s *testIntegrationSuite) TestTimeLiteral(c *C) {
}

func (s *testIntegrationSuite) TestTimestampLiteral(c *C) {
defer func() {
s.cleanEnv(c)
testleak.AfterTest(c)()
}()

defer s.cleanEnv(c)
tk := testkit.NewTestKit(c, s.store)

r := tk.MustQuery("select timestamp '2017-01-01 00:00:00';")
Expand Down Expand Up @@ -2853,22 +2797,15 @@ func (s *testIntegrationSuite) TestTimestampLiteral(c *C) {
}

func (s *testIntegrationSuite) TestLiterals(c *C) {
defer func() {
s.cleanEnv(c)
testleak.AfterTest(c)()
}()

defer s.cleanEnv(c)
tk := testkit.NewTestKit(c, s.store)
r := tk.MustQuery("SELECT LENGTH(b''), LENGTH(B''), b''+1, b''-1, B''+1;")
r.Check(testkit.Rows("0 0 1 -1 1"))
}

func (s *testIntegrationSuite) TestFuncJSON(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
defer s.cleanEnv(c)
tk.MustExec("USE test;")
tk.MustExec("DROP TABLE IF EXISTS table_json;")
tk.MustExec("CREATE TABLE table_json(a json, b VARCHAR(255));")
Expand Down Expand Up @@ -2910,10 +2847,7 @@ func (s *testIntegrationSuite) TestFuncJSON(c *C) {

func (s *testIntegrationSuite) TestColumnInfoModified(c *C) {
testKit := testkit.NewTestKit(c, s.store)
defer func() {
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
defer s.cleanEnv(c)
testKit.MustExec("use test")
testKit.MustExec("drop table if exists tab0")
testKit.MustExec("CREATE TABLE tab0(col0 INTEGER, col1 INTEGER, col2 INTEGER)")
Expand All @@ -2927,10 +2861,7 @@ func (s *testIntegrationSuite) TestColumnInfoModified(c *C) {

func (s *testIntegrationSuite) TestSetVariables(c *C) {
tk := testkit.NewTestKit(c, s.store)
defer func() {
s.cleanEnv(c)
testleak.AfterTest(c)()
}()
defer s.cleanEnv(c)
_, err := tk.Exec("set sql_mode='adfasdfadsfdasd';")
c.Assert(err, NotNil)
_, err = tk.Exec("set @@sql_mode='adfasdfadsfdasd';")
Expand Down

0 comments on commit 834d51f

Please sign in to comment.