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

planner/core: migrate leak tests to goleak #27433

Merged
merged 17 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
31 changes: 31 additions & 0 deletions planner/core/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2021 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package core

import (
"testing"

"github.com/pingcap/tidb/util/testbridge"
"go.uber.org/goleak"
)

func TestMain(m *testing.M) {
testbridge.WorkaroundGoCheckFlags()
opts := []goleak.Option{
goleak.IgnoreTopFunction("go.etcd.io/etcd/pkg/logutil.(*MergeLogger).outputLoop"),
goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"),
}
goleak.VerifyTestMain(m, opts...)
}
24 changes: 7 additions & 17 deletions planner/core/preprocess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ func (s *testValidatorSuite) SetUpTest(c *C) {
s.is = infoschema.MockInfoSchema([]*model.TableInfo{core.MockSignedTable()})
}

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

func (s *testValidatorSuite) runSQL(c *C, sql string, inPrepare bool, terr error) {
stmts, err1 := session.Parse(s.ctx, sql)
c.Assert(err1, IsNil, Commentf("sql: %s", sql))
Expand All @@ -73,11 +80,6 @@ func (s *testValidatorSuite) runSQL(c *C, sql string, inPrepare bool, terr error
}

func (s *testValidatorSuite) TestValidator(c *C) {
defer testleak.AfterTest(c)()
defer func() {
s.dom.Close()
s.store.Close()
}()
tests := []struct {
sql string
inPrepare bool
Expand Down Expand Up @@ -315,12 +317,6 @@ func (s *testValidatorSuite) TestValidator(c *C) {
}

func (s *testValidatorSuite) TestForeignKey(c *C) {
defer testleak.AfterTest(c)()
defer func() {
s.dom.Close()
s.store.Close()
}()

_, err := s.se.Execute(context.Background(), "create table test.t1(a int, b int, c int)")
c.Assert(err, IsNil)

Expand All @@ -346,12 +342,6 @@ func (s *testValidatorSuite) TestForeignKey(c *C) {
}

func (s *testValidatorSuite) TestDropGlobalTempTable(c *C) {
defer testleak.AfterTest(c)()
defer func() {
s.dom.Close()
s.store.Close()
}()

ctx := context.Background()
execSQLList := []string{
"use test",
Expand Down
7 changes: 7 additions & 0 deletions planner/core/rule_result_reorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ func (s *testRuleReorderResultsSerial) SetUpTest(c *C) {
c.Assert(err, IsNil)
}

func (s *testRuleReorderResultsSerial) TearDownTest(c *C) {
s.dom.Close()
c.Assert(s.store.Close(), IsNil)
}

func (s *testRuleReorderResultsSerial) TestPlanCache(c *C) {
tk := testkit.NewTestKit(c, s.store)
orgEnable := plannercore.PreparedPlanCacheEnabled()
Expand Down Expand Up @@ -124,6 +129,8 @@ func (s *testRuleReorderResults) SetUpSuite(c *C) {
}

func (s *testRuleReorderResults) TearDownSuite(c *C) {
s.dom.Close()
c.Assert(s.store.Close(), IsNil)
c.Assert(s.testData.GenerateOutputIfNeeded(), IsNil)
}

Expand Down