Skip to content

Commit

Permalink
*: Add leak test
Browse files Browse the repository at this point in the history
* *: add leak test and tiny clean up

* *: unify test format and add leak test

Conflicts:
	store/localstore/compactor_test.go
	mysql/error_test.go
*: add leak test
  • Loading branch information
zimulala committed Apr 7, 2016
1 parent eb941fb commit 0803454
Show file tree
Hide file tree
Showing 80 changed files with 5,116 additions and 25 deletions.
5 changes: 5 additions & 0 deletions column/column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
. "github.com/pingcap/check"
"github.com/pingcap/tidb/model"
"github.com/pingcap/tidb/mysql"
"github.com/pingcap/tidb/util/testleak"
"github.com/pingcap/tidb/util/types"
)

Expand All @@ -31,6 +32,7 @@ func TestT(t *testing.T) {
type testColumnSuite struct{}

func (s *testColumnSuite) TestString(c *C) {
defer testleak.AfterTest(c)()
col := &Col{
model.ColumnInfo{
FieldType: *types.NewFieldType(mysql.TypeTiny),
Expand Down Expand Up @@ -75,6 +77,7 @@ func (s *testColumnSuite) TestString(c *C) {
}

func (s *testColumnSuite) TestFind(c *C) {
defer testleak.AfterTest(c)()
cols := []*Col{
newCol("a"),
newCol("b"),
Expand All @@ -87,6 +90,7 @@ func (s *testColumnSuite) TestFind(c *C) {
}

func (s *testColumnSuite) TestCheck(c *C) {
defer testleak.AfterTest(c)()
col := newCol("a")
col.Flag = mysql.AutoIncrementFlag
cols := []*Col{col, col}
Expand All @@ -98,6 +102,7 @@ func (s *testColumnSuite) TestCheck(c *C) {
}

func (s *testColumnSuite) TestDesc(c *C) {
defer testleak.AfterTest(c)()
col := newCol("a")
col.Flag = mysql.AutoIncrementFlag | mysql.NotNullFlag | mysql.PriKeyFlag
NewColDesc(col)
Expand Down
4 changes: 4 additions & 0 deletions ddl/bg_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import (
"github.com/pingcap/tidb/meta"
"github.com/pingcap/tidb/model"
"github.com/pingcap/tidb/util/mock"
"github.com/pingcap/tidb/util/testleak"
)

func (s *testDDLSuite) TestDropSchemaError(c *C) {
defer testleak.AfterTest(c)()
store := testCreateStore(c, "test_drop_schema")
defer store.Close()

Expand Down Expand Up @@ -58,6 +60,7 @@ func verifyBgJobState(c *C, d *ddl, job *model.Job, state model.JobState) {
}

func (s *testDDLSuite) TestDropTableError(c *C) {
defer testleak.AfterTest(c)()
store := testCreateStore(c, "test_drop_table")
defer store.Close()

Expand All @@ -84,6 +87,7 @@ func (s *testDDLSuite) TestDropTableError(c *C) {
}

func (s *testDDLSuite) TestInvalidBgJobType(c *C) {
defer testleak.AfterTest(c)()
store := testCreateStore(c, "test_invalid_bg_job_type")
defer store.Close()

Expand Down
2 changes: 2 additions & 0 deletions ddl/callback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package ddl
import (
. "github.com/pingcap/check"
"github.com/pingcap/tidb/model"
"github.com/pingcap/tidb/util/testleak"
)

type testDDLCallback struct {
Expand Down Expand Up @@ -44,6 +45,7 @@ func (tc *testDDLCallback) OnJobUpdated(job *model.Job) {
}

func (s *testDDLSuite) TestCallback(c *C) {
defer testleak.AfterTest(c)()
cb := &BaseCallback{}
c.Assert(cb.OnChanged(nil), IsNil)
cb.OnJobRunBefore(nil)
Expand Down
4 changes: 4 additions & 0 deletions ddl/column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/table/tables"
"github.com/pingcap/tidb/util/mock"
"github.com/pingcap/tidb/util/testleak"
"github.com/pingcap/tidb/util/types"
)

Expand Down Expand Up @@ -104,6 +105,7 @@ func testDropColumn(c *C, ctx context.Context, d *ddl, dbInfo *model.DBInfo, tbl
}

func (s *testColumnSuite) TestColumn(c *C) {
defer testleak.AfterTest(c)()
tblInfo := testTableInfo(c, s.d, "t1", 3)
ctx := testNewContext(c, s.d)
defer ctx.FinishTxn(true)
Expand Down Expand Up @@ -550,6 +552,7 @@ func (s *testColumnSuite) testGetColumn(c *C, t table.Table, name string, isExis
}

func (s *testColumnSuite) TestAddColumn(c *C) {
defer testleak.AfterTest(c)()
d := newDDL(s.store, nil, nil, 100*time.Millisecond)
tblInfo := testTableInfo(c, d, "t", 3)
ctx := testNewContext(c, d)
Expand Down Expand Up @@ -616,6 +619,7 @@ func (s *testColumnSuite) TestAddColumn(c *C) {
}

func (s *testColumnSuite) TestDropColumn(c *C) {
defer testleak.AfterTest(c)()
d := newDDL(s.store, nil, nil, 100*time.Millisecond)
tblInfo := testTableInfo(c, d, "t", 4)
ctx := testNewContext(c, d)
Expand Down
3 changes: 3 additions & 0 deletions ddl/ddl_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/terror"
"github.com/pingcap/tidb/util/testleak"
"github.com/pingcap/tidb/util/types"
)

Expand Down Expand Up @@ -91,6 +92,7 @@ func (s *testDBSuite) TearDownSuite(c *C) {
}

func (s *testDBSuite) TestIndex(c *C) {
defer testleak.AfterTest(c)()
s.testAddIndex(c)
s.testDropIndex(c)
}
Expand Down Expand Up @@ -309,6 +311,7 @@ func (s *testDBSuite) showColumns(c *C, tableName string) [][]interface{} {
}

func (s *testDBSuite) TestColumn(c *C) {
defer testleak.AfterTest(c)()
s.testAddColumn(c)
s.testDropColumn(c)
}
Expand Down
6 changes: 6 additions & 0 deletions ddl/ddl_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/pingcap/tidb/store/localstore"
"github.com/pingcap/tidb/store/localstore/goleveldb"
"github.com/pingcap/tidb/terror"
"github.com/pingcap/tidb/util/testleak"
"github.com/pingcap/tidb/util/types"
)

Expand Down Expand Up @@ -65,6 +66,7 @@ func testCheckOwner(c *C, d *ddl, isOwner bool, flag JobType) {
}

func (s *testDDLSuite) TestCheckOwner(c *C) {
defer testleak.AfterTest(c)()
store := testCreateStore(c, "test_owner")
defer store.Close()

Expand Down Expand Up @@ -109,6 +111,7 @@ func (s *testDDLSuite) TestCheckOwner(c *C) {
}

func (s *testDDLSuite) TestSchemaError(c *C) {
defer testleak.AfterTest(c)()
store := testCreateStore(c, "test_schema_error")
defer store.Close()

Expand All @@ -131,6 +134,7 @@ func (s *testDDLSuite) TestSchemaError(c *C) {
}

func (s *testDDLSuite) TestTableError(c *C) {
defer testleak.AfterTest(c)()
store := testCreateStore(c, "test_table_error")
defer store.Close()

Expand Down Expand Up @@ -201,6 +205,7 @@ func (s *testDDLSuite) TestTableError(c *C) {
}

func (s *testDDLSuite) TestIndexError(c *C) {
defer testleak.AfterTest(c)()
store := testCreateStore(c, "test_index_error")
defer store.Close()

Expand Down Expand Up @@ -303,6 +308,7 @@ func (s *testDDLSuite) TestIndexError(c *C) {
}

func (s *testDDLSuite) TestColumnError(c *C) {
defer testleak.AfterTest(c)()
store := testCreateStore(c, "test_column_error")
defer store.Close()

Expand Down
4 changes: 4 additions & 0 deletions ddl/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/table/tables"
"github.com/pingcap/tidb/util/mock"
"github.com/pingcap/tidb/util/testleak"
"github.com/pingcap/tidb/util/types"
)

Expand Down Expand Up @@ -88,6 +89,7 @@ func testDropIndex(c *C, ctx context.Context, d *ddl, dbInfo *model.DBInfo, tblI
}

func (s *testIndexSuite) TestIndex(c *C) {
defer testleak.AfterTest(c)()
tblInfo := testTableInfo(c, s.d, "t1", 3)
ctx := testNewContext(c, s.d)
defer ctx.FinishTxn(true)
Expand Down Expand Up @@ -562,6 +564,7 @@ func (s *testIndexSuite) checkAddOrDropIndex(c *C, state model.SchemaState, d *d
}

func (s *testIndexSuite) TestAddIndex(c *C) {
defer testleak.AfterTest(c)()
d := newDDL(s.store, nil, nil, 100*time.Millisecond)
tblInfo := testTableInfo(c, d, "t", 3)
ctx := testNewContext(c, d)
Expand Down Expand Up @@ -629,6 +632,7 @@ func (s *testIndexSuite) TestAddIndex(c *C) {
}

func (s *testIndexSuite) TestDropIndex(c *C) {
defer testleak.AfterTest(c)()
d := newDDL(s.store, nil, nil, 100*time.Millisecond)
tblInfo := testTableInfo(c, d, "t", 3)
ctx := testNewContext(c, d)
Expand Down
3 changes: 3 additions & 0 deletions ddl/reorg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/meta"
"github.com/pingcap/tidb/model"
"github.com/pingcap/tidb/util/testleak"
"github.com/pingcap/tidb/util/types"
)

Expand All @@ -32,6 +33,7 @@ func (k testCtxKeyType) String() string {
const testCtxKey testCtxKeyType = 0

func (s *testDDLSuite) TestReorg(c *C) {
defer testleak.AfterTest(c)()
store := testCreateStore(c, "test_reorg")
defer store.Close()

Expand Down Expand Up @@ -112,6 +114,7 @@ func (s *testDDLSuite) TestReorg(c *C) {
}

func (s *testDDLSuite) TestReorgOwner(c *C) {
defer testleak.AfterTest(c)()
store := testCreateStore(c, "test_reorg_owner")
defer store.Close()

Expand Down
4 changes: 4 additions & 0 deletions ddl/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/pingcap/tidb/model"
"github.com/pingcap/tidb/terror"
"github.com/pingcap/tidb/util/mock"
"github.com/pingcap/tidb/util/testleak"
)

var _ = Suite(&testSchemaSuite{})
Expand Down Expand Up @@ -131,6 +132,7 @@ func testCheckJobCancelled(c *C, d *ddl, job *model.Job) {
}

func (s *testSchemaSuite) TestSchema(c *C) {
defer testleak.AfterTest(c)()
store := testCreateStore(c, "test_schema")
defer store.Close()

Expand Down Expand Up @@ -161,6 +163,7 @@ func (s *testSchemaSuite) TestSchema(c *C) {
}

func (s *testSchemaSuite) TestSchemaWaitJob(c *C) {
defer testleak.AfterTest(c)()
store := testCreateStore(c, "test_schema_wait")
defer store.Close()

Expand Down Expand Up @@ -227,6 +230,7 @@ LOOP:
}

func (s *testSchemaSuite) TestSchemaResume(c *C) {
defer testleak.AfterTest(c)()
store := testCreateStore(c, "test_schema_resume")
defer store.Close()

Expand Down
2 changes: 2 additions & 0 deletions ddl/stat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
. "github.com/pingcap/check"
"github.com/pingcap/tidb/model"
"github.com/pingcap/tidb/util/mock"
"github.com/pingcap/tidb/util/testleak"
)

var _ = Suite(&testStatSuite{})
Expand All @@ -34,6 +35,7 @@ func (s *testStatSuite) getDDLSchemaVer(c *C, d *ddl) int64 {
}

func (s *testStatSuite) TestStat(c *C) {
defer testleak.AfterTest(c)()
store := testCreateStore(c, "test_stat")
defer store.Close()

Expand Down
3 changes: 3 additions & 0 deletions ddl/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/util/mock"
"github.com/pingcap/tidb/util/testleak"
"github.com/pingcap/tidb/util/types"
)

Expand Down Expand Up @@ -149,6 +150,7 @@ func testNewContext(c *C, d *ddl) context.Context {
}

func (s *testTableSuite) TestTable(c *C) {
defer testleak.AfterTest(c)()
d := s.d

ctx := testNewContext(c, d)
Expand Down Expand Up @@ -185,6 +187,7 @@ func (s *testTableSuite) TestTable(c *C) {
}

func (s *testTableSuite) TestTableResume(c *C) {
defer testleak.AfterTest(c)()
d := s.d

testCheckOwner(c, d, true, ddlJobFlag)
Expand Down
4 changes: 4 additions & 0 deletions evaluator/builtin_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import (
"errors"

. "github.com/pingcap/check"
"github.com/pingcap/tidb/util/testleak"
"github.com/pingcap/tidb/util/types"
)

func (s *testEvaluatorSuite) TestIf(c *C) {
defer testleak.AfterTest(c)()
tbl := []struct {
Arg1 interface{}
Arg2 interface{}
Expand All @@ -43,6 +45,7 @@ func (s *testEvaluatorSuite) TestIf(c *C) {
}

func (s *testEvaluatorSuite) TestIfNull(c *C) {
defer testleak.AfterTest(c)()
tbl := []struct {
Arg1 interface{}
Arg2 interface{}
Expand All @@ -61,6 +64,7 @@ func (s *testEvaluatorSuite) TestIfNull(c *C) {
}

func (s *testEvaluatorSuite) TestNullIf(c *C) {
defer testleak.AfterTest(c)()
tbl := []struct {
Arg1 interface{}
Arg2 interface{}
Expand Down
7 changes: 7 additions & 0 deletions evaluator/builtin_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ import (
"github.com/pingcap/tidb/sessionctx/db"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/util/mock"
"github.com/pingcap/tidb/util/testleak"
"github.com/pingcap/tidb/util/types"
)

func (s *testEvaluatorSuite) TestDatabase(c *C) {
defer testleak.AfterTest(c)()
ctx := mock.NewContext()
d, err := builtinDatabase(types.MakeDatums(), ctx)
c.Assert(err, IsNil)
Expand All @@ -35,6 +37,7 @@ func (s *testEvaluatorSuite) TestDatabase(c *C) {
}

func (s *testEvaluatorSuite) TestFoundRows(c *C) {
defer testleak.AfterTest(c)()
ctx := mock.NewContext()
d, err := builtinFoundRows(types.MakeDatums(), ctx)
c.Assert(err, NotNil)
Expand All @@ -47,6 +50,7 @@ func (s *testEvaluatorSuite) TestFoundRows(c *C) {
}

func (s *testEvaluatorSuite) TestUser(c *C) {
defer testleak.AfterTest(c)()
ctx := mock.NewContext()
variable.BindSessionVars(ctx)
sessionVars := variable.GetSessionVars(ctx)
Expand All @@ -58,6 +62,7 @@ func (s *testEvaluatorSuite) TestUser(c *C) {
}

func (s *testEvaluatorSuite) TestCurrentUser(c *C) {
defer testleak.AfterTest(c)()
ctx := mock.NewContext()
variable.BindSessionVars(ctx)
sessionVars := variable.GetSessionVars(ctx)
Expand All @@ -69,6 +74,7 @@ func (s *testEvaluatorSuite) TestCurrentUser(c *C) {
}

func (s *testEvaluatorSuite) TestConnectionID(c *C) {
defer testleak.AfterTest(c)()
ctx := mock.NewContext()
variable.BindSessionVars(ctx)
sessionVars := variable.GetSessionVars(ctx)
Expand All @@ -80,6 +86,7 @@ func (s *testEvaluatorSuite) TestConnectionID(c *C) {
}

func (s *testEvaluatorSuite) TestVersion(c *C) {
defer testleak.AfterTest(c)()
ctx := mock.NewContext()
v, err := builtinVersion(nil, ctx)
c.Assert(err, IsNil)
Expand Down
Loading

0 comments on commit 0803454

Please sign in to comment.