Skip to content

Commit

Permalink
use setup teardown
Browse files Browse the repository at this point in the history
  • Loading branch information
feitian124 committed Aug 24, 2021
1 parent 23fb97f commit aa63353
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
17 changes: 0 additions & 17 deletions table/tables/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ import (
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/table/tables"
"github.com/pingcap/tidb/tablecodec"
Expand All @@ -47,16 +45,6 @@ type testIndexSuite struct {
dom *domain.Domain
}

var s = testIndexSuite{}

func TestSetUpSuite(t *testing.T) {
store, err := mockstore.NewMockStore()
require.Nil(t, err)
s.s = store
s.dom, err = session.BootstrapSession(store)
require.Nil(t, err)
}

func TestIndex(t *testing.T) {
tblInfo := &model.TableInfo{
ID: 1,
Expand Down Expand Up @@ -399,8 +387,3 @@ func buildTableInfo(t *testing.T, sql string) *model.TableInfo {
return tblInfo
}

func TestTearDownSuite(t *testing.T) {
s.dom.Close()
err := s.s.Close()
require.Nil(t, err)
}
35 changes: 35 additions & 0 deletions table/tables/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,53 @@
package tables_test

import (
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/store/mockstore"
"log"
"os"
"testing"

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

var s = testIndexSuite{}

func TestMain(m *testing.M) {
testbridge.WorkaroundGoCheckFlags()

setUpIndexSuite()
exitCode := m.Run()
tearDownIndexSuite()
if exitCode != 0 {
os.Exit(exitCode)
}

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...)
}

func setUpIndexSuite() {
println("setUpIndexSuite")
store, err := mockstore.NewMockStore()
if err != nil {
log.Fatal(err)
}
s.s = store
s.dom, err = session.BootstrapSession(store)
if err != nil {
log.Fatal(err)
}
}

func tearDownIndexSuite() {
println("tearDownIndexSuite")
s.dom.Close()
err := s.s.Close()
if err != nil {
log.Fatal(err)
}
}

0 comments on commit aa63353

Please sign in to comment.