Skip to content

Commit

Permalink
plan,statistics: don't forget to close domain in testing (pingcap#4591)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored and coocood committed Sep 20, 2017
1 parent 346b7c7 commit fe31f4b
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 74 deletions.
30 changes: 14 additions & 16 deletions plan/cbo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
. "github.com/pingcap/check"
"github.com/pingcap/tidb"
"github.com/pingcap/tidb/context"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/expression"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/plan"
Expand All @@ -46,13 +47,12 @@ func constructInsertSQL(i, n int) string {
}

func (s *testAnalyzeSuite) TestIndexRead(c *C) {
defer func() {
testleak.AfterTest(c)()
}()
store, err := newStoreWithBootstrap()
defer testleak.AfterTest(c)()
store, dom, err := newStoreWithBootstrap()
c.Assert(err, IsNil)
testKit := testkit.NewTestKit(c, store)
defer func() {
dom.Close()
store.Close()
}()
testKit.MustExec("use test")
Expand Down Expand Up @@ -164,13 +164,12 @@ func (s *testAnalyzeSuite) TestIndexRead(c *C) {
}

func (s *testAnalyzeSuite) TestEmptyTable(c *C) {
defer func() {
testleak.AfterTest(c)()
}()
store, err := newStoreWithBootstrap()
defer testleak.AfterTest(c)()
store, dom, err := newStoreWithBootstrap()
c.Assert(err, IsNil)
testKit := testkit.NewTestKit(c, store)
defer func() {
dom.Close()
store.Close()
}()
testKit.MustExec("use test")
Expand Down Expand Up @@ -216,13 +215,12 @@ func (s *testAnalyzeSuite) TestEmptyTable(c *C) {
}

func (s *testAnalyzeSuite) TestAnalyze(c *C) {
defer func() {
testleak.AfterTest(c)()
}()
store, err := newStoreWithBootstrap()
defer testleak.AfterTest(c)()
store, dom, err := newStoreWithBootstrap()
c.Assert(err, IsNil)
testKit := testkit.NewTestKit(c, store)
defer func() {
dom.Close()
store.Close()
}()
testKit.MustExec("use test")
Expand Down Expand Up @@ -303,13 +301,13 @@ func (s *testAnalyzeSuite) TestAnalyze(c *C) {
}
}

func newStoreWithBootstrap() (kv.Storage, error) {
func newStoreWithBootstrap() (kv.Storage, *domain.Domain, error) {
store, err := tikv.NewMockTikvStore()
if err != nil {
return nil, errors.Trace(err)
return nil, nil, errors.Trace(err)
}
tidb.SetSchemaLease(0)
tidb.SetStatsLease(0)
_, err = tidb.BootstrapSession(store)
return store, errors.Trace(err)
dom, err := tidb.BootstrapSession(store)
return store, dom, errors.Trace(err)
}
99 changes: 54 additions & 45 deletions plan/dag_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ func (s *testPlanSuite) SetUpSuite(c *C) {
}

func (s *testPlanSuite) TestDAGPlanBuilderSimpleCase(c *C) {
store, err := newStoreWithBootstrap()
defer testleak.AfterTest(c)()
store, dom, err := newStoreWithBootstrap()
c.Assert(err, IsNil)
defer store.Close()
defer func() {
dom.Close()
store.Close()
}()
se, err := tidb.CreateSession(store)
c.Assert(err, IsNil)

defer func() {
testleak.AfterTest(c)()
}()
tests := []struct {
sql string
best string
Expand Down Expand Up @@ -185,15 +186,16 @@ func (s *testPlanSuite) TestDAGPlanBuilderSimpleCase(c *C) {
}

func (s *testPlanSuite) TestDAGPlanBuilderJoin(c *C) {
store, err := newStoreWithBootstrap()
defer testleak.AfterTest(c)()
store, dom, err := newStoreWithBootstrap()
c.Assert(err, IsNil)
defer store.Close()
defer func() {
dom.Close()
store.Close()
}()
se, err := tidb.CreateSession(store)
c.Assert(err, IsNil)

defer func() {
testleak.AfterTest(c)()
}()
tests := []struct {
sql string
best string
Expand Down Expand Up @@ -350,15 +352,16 @@ func (s *testPlanSuite) TestDAGPlanBuilderJoin(c *C) {
}

func (s *testPlanSuite) TestDAGPlanBuilderSubquery(c *C) {
store, err := newStoreWithBootstrap()
defer testleak.AfterTest(c)()
store, dom, err := newStoreWithBootstrap()
c.Assert(err, IsNil)
defer store.Close()
defer func() {
dom.Close()
store.Close()
}()
se, err := tidb.CreateSession(store)
c.Assert(err, IsNil)

defer func() {
testleak.AfterTest(c)()
}()
tests := []struct {
sql string
best string
Expand Down Expand Up @@ -419,15 +422,16 @@ func (s *testPlanSuite) TestDAGPlanBuilderSubquery(c *C) {
}

func (s *testPlanSuite) TestDAGPlanTopN(c *C) {
store, err := newStoreWithBootstrap()
defer testleak.AfterTest(c)()
store, dom, err := newStoreWithBootstrap()
c.Assert(err, IsNil)
defer store.Close()
defer func() {
dom.Close()
store.Close()
}()
se, err := tidb.CreateSession(store)
c.Assert(err, IsNil)

defer func() {
testleak.AfterTest(c)()
}()
tests := []struct {
sql string
best string
Expand Down Expand Up @@ -475,15 +479,16 @@ func (s *testPlanSuite) TestDAGPlanTopN(c *C) {
}

func (s *testPlanSuite) TestDAGPlanBuilderBasePhysicalPlan(c *C) {
store, err := newStoreWithBootstrap()
defer testleak.AfterTest(c)()
store, dom, err := newStoreWithBootstrap()
c.Assert(err, IsNil)
defer store.Close()
defer func() {
dom.Close()
store.Close()
}()
se, err := tidb.CreateSession(store)
c.Assert(err, IsNil)

defer func() {
testleak.AfterTest(c)()
}()
tests := []struct {
sql string
best string
Expand Down Expand Up @@ -554,15 +559,16 @@ func (s *testPlanSuite) TestDAGPlanBuilderBasePhysicalPlan(c *C) {
}

func (s *testPlanSuite) TestDAGPlanBuilderUnion(c *C) {
store, err := newStoreWithBootstrap()
defer testleak.AfterTest(c)()
store, dom, err := newStoreWithBootstrap()
c.Assert(err, IsNil)
defer store.Close()
defer func() {
dom.Close()
store.Close()
}()
se, err := tidb.CreateSession(store)
c.Assert(err, IsNil)

defer func() {
testleak.AfterTest(c)()
}()
tests := []struct {
sql string
best string
Expand Down Expand Up @@ -602,15 +608,16 @@ func (s *testPlanSuite) TestDAGPlanBuilderUnion(c *C) {
}

func (s *testPlanSuite) TestDAGPlanBuilderUnionScan(c *C) {
store, err := newStoreWithBootstrap()
defer testleak.AfterTest(c)()
store, dom, err := newStoreWithBootstrap()
c.Assert(err, IsNil)
defer store.Close()
defer func() {
dom.Close()
store.Close()
}()
se, err := tidb.CreateSession(store)
c.Assert(err, IsNil)

defer func() {
testleak.AfterTest(c)()
}()
tests := []struct {
sql string
best string
Expand Down Expand Up @@ -668,15 +675,16 @@ func (s *testPlanSuite) TestDAGPlanBuilderUnionScan(c *C) {
}

func (s *testPlanSuite) TestDAGPlanBuilderAgg(c *C) {
store, err := newStoreWithBootstrap()
defer testleak.AfterTest(c)()
store, dom, err := newStoreWithBootstrap()
c.Assert(err, IsNil)
defer store.Close()
defer func() {
dom.Close()
store.Close()
}()
se, err := tidb.CreateSession(store)
c.Assert(err, IsNil)

defer func() {
testleak.AfterTest(c)()
}()
tests := []struct {
sql string
best string
Expand Down Expand Up @@ -802,15 +810,16 @@ func (s *testPlanSuite) TestDAGPlanBuilderAgg(c *C) {
}

func (s *testPlanSuite) TestRefine(c *C) {
store, err := newStoreWithBootstrap()
defer testleak.AfterTest(c)()
store, dom, err := newStoreWithBootstrap()
c.Assert(err, IsNil)
defer store.Close()
defer func() {
dom.Close()
store.Close()
}()
se, err := tidb.CreateSession(store)
c.Assert(err, IsNil)

defer func() {
testleak.AfterTest(c)()
}()
tests := []struct {
sql string
best string
Expand Down
8 changes: 5 additions & 3 deletions plan/explain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ type testExplainSuite struct {
}

func (s *testExplainSuite) TestExplain(c *C) {
store, err := newStoreWithBootstrap()
defer testleak.AfterTest(c)()
store, dom, err := newStoreWithBootstrap()
c.Assert(err, IsNil)
tk := testkit.NewTestKit(c, store)
defer func() {
testleak.AfterTest(c)()
dom.Close()
store.Close()
}()
tk := testkit.NewTestKit(c, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1, t2, t3")
tk.MustExec("create table t1 (c1 int primary key, c2 int, c3 int, index c2 (c2))")
Expand Down
7 changes: 5 additions & 2 deletions plan/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,12 @@ var resolverTests = []resolverTestCase{
}

func (ts *testNameResolverSuite) TestNameResolver(c *C) {
store, err := newStoreWithBootstrap()
store, dom, err := newStoreWithBootstrap()
c.Assert(err, IsNil)
defer store.Close()
defer func() {
dom.Close()
store.Close()
}()
testKit := testkit.NewTestKit(c, store)
testKit.MustExec("use test")
testKit.MustExec("create table t1 (c1 int, c2 int)")
Expand Down
7 changes: 5 additions & 2 deletions plan/typeinfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ type typeInferTestCase struct {
}

func (s *testPlanSuite) TestInferType(c *C) {
store, err := newStoreWithBootstrap()
store, dom, err := newStoreWithBootstrap()
c.Assert(err, IsNil)
defer store.Close()
defer func() {
dom.Close()
store.Close()
}()
se, err := tidb.CreateSession(store)
c.Assert(err, IsNil)
defer func() {
Expand Down
7 changes: 5 additions & 2 deletions plan/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,12 @@ func (s *testValidatorSuite) TestValidator(c *C) {
{`select sum(1 in (select count(1)))`, true, nil},
}

store, err := tidb.NewStore(tidb.EngineGoLevelDBMemory)
store, dom, err := newStoreWithBootstrap()
c.Assert(err, IsNil)
defer store.Close()
defer func() {
dom.Close()
store.Close()
}()
se, err := tidb.CreateSession(store)
c.Assert(err, IsNil)
for _, tt := range tests {
Expand Down
10 changes: 6 additions & 4 deletions statistics/selectivity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,19 @@ func mockStatsTable(tbl *model.TableInfo, rowCount int64) *statistics.Table {
}

func (s *testSelectivitySuite) TestSelectivity(c *C) {
store, do, err := newStoreWithBootstrap()
defer store.Close()
store, dom, err := newStoreWithBootstrap()
defer func() {
dom.Close()
store.Close()
}()
c.Assert(err, IsNil)
defer do.Close()

testKit := testkit.NewTestKit(c, store)
testKit.MustExec("use test")
testKit.MustExec("drop table if exists t")
testKit.MustExec("create table t(a int primary key, b int, c int, d int, e int, index idx_cd(c, d), index idx_de(d, e))")

is := do.InfoSchema()
is := dom.InfoSchema()
tb, err := is.TableByName(model.NewCIStr("test"), model.NewCIStr("t"))
c.Assert(err, IsNil)
tbl := tb.Meta()
Expand Down
1 change: 1 addition & 0 deletions util/testleak/leaktest.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func interestingGoroutines() (gs []string) {
strings.Contains(stack, "created by github.com/pingcap/tidb.init") ||
strings.Contains(stack, "testing.RunTests") ||
strings.Contains(stack, "check.(*resultTracker).start") ||
strings.Contains(stack, "check.(*suiteRunner).runFunc") ||
strings.Contains(stack, "localstore.(*dbStore).scheduler") ||
strings.Contains(stack, "ddl.(*ddl).start") ||
strings.Contains(stack, "ddl.(*delRange).startEmulator") ||
Expand Down

0 comments on commit fe31f4b

Please sign in to comment.