Skip to content

Commit

Permalink
statistics,executor: fix some unit tests that run twice (#22705)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored Feb 5, 2021
1 parent 8ddaf03 commit 9a2997f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
10 changes: 4 additions & 6 deletions executor/clustered_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ import (
"github.com/pingcap/tidb/util/testkit"
)

type testClusteredSuite struct{ *baseTestSuite }
type testClusteredSerialSuite struct{ *testClusteredSuite }
type testClusteredSuiteBase struct{ baseTestSuite }
type testClusteredSuite struct{ testClusteredSuiteBase }
type testClusteredSerialSuite struct{ testClusteredSuiteBase }

func (s *testClusteredSuite) SetUpTest(c *C) {
}

func (s *testClusteredSuite) newTK(c *C) *testkit.TestKit {
func (s *testClusteredSuiteBase) newTK(c *C) *testkit.TestKit {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("set @@tidb_enable_clustered_index = 1")
return tk
Expand Down
4 changes: 2 additions & 2 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ var _ = Suite(&testSuiteAgg{baseTestSuite: &baseTestSuite{}})
var _ = Suite(&testSuite6{&baseTestSuite{}})
var _ = Suite(&testSuite7{&baseTestSuite{}})
var _ = Suite(&testSuite8{&baseTestSuite{}})
var _ = Suite(&testClusteredSuite{&baseTestSuite{}})
var _ = SerialSuites(&testClusteredSerialSuite{&testClusteredSuite{&baseTestSuite{}}})
var _ = Suite(&testClusteredSuite{})
var _ = SerialSuites(&testClusteredSerialSuite{})
var _ = SerialSuites(&testShowStatsSuite{&baseTestSuite{}})
var _ = Suite(&testBypassSuite{})
var _ = Suite(&testUpdateSuite{})
Expand Down
4 changes: 2 additions & 2 deletions statistics/handle/handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -840,10 +840,10 @@ func (s *testStatsSuite) TestCorrelationStatsCompute(c *C) {
c.Assert(foundS1 && foundS2, IsTrue)
}

var _ = SerialSuites(&statsSerialSuite{&testStatsSuite{}})
var _ = SerialSuites(&statsSerialSuite{})

type statsSerialSuite struct {
*testStatsSuite
testSuiteBase
}

func (s *statsSerialSuite) TestIndexUsageInformation(c *C) {
Expand Down
12 changes: 8 additions & 4 deletions statistics/handle/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,17 @@ func (s *testSerialStatsSuite) TearDownSuite(c *C) {
testleak.AfterTest(c)()
}

type testStatsSuite struct {
type testSuiteBase struct {
store kv.Storage
do *domain.Domain
hook *logHook
}

func (s *testStatsSuite) SetUpSuite(c *C) {
type testStatsSuite struct {
testSuiteBase
}

func (s *testSuiteBase) SetUpSuite(c *C) {
testleak.BeforeTest()
// Add the hook here to avoid data race.
s.registerHook()
Expand All @@ -80,13 +84,13 @@ func (s *testStatsSuite) SetUpSuite(c *C) {
c.Assert(err, IsNil)
}

func (s *testStatsSuite) TearDownSuite(c *C) {
func (s *testSuiteBase) TearDownSuite(c *C) {
s.do.Close()
s.store.Close()
testleak.AfterTest(c)()
}

func (s *testStatsSuite) registerHook() {
func (s *testSuiteBase) registerHook() {
conf := &log.Config{Level: os.Getenv("log_level"), File: log.FileLogConfig{}}
_, r, _ := log.InitLogger(conf)
s.hook = &logHook{r.Core, ""}
Expand Down

0 comments on commit 9a2997f

Please sign in to comment.