Skip to content

Commit

Permalink
*: move InitLogger from SetUpSuite to TestT (pingcap#4532)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored and zz-jason committed Sep 15, 2017
1 parent 1006dab commit 117ff28
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 36 deletions.
11 changes: 4 additions & 7 deletions ddl/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ import (

func TestT(t *testing.T) {
CustomVerboseFlag = true
logLevel := os.Getenv("log_level")
logutil.InitLogger(&logutil.LogConfig{
Level: logLevel,
})
TestingT(t)
}

Expand Down Expand Up @@ -143,10 +147,3 @@ func testDropIndex(c *C, ctx context.Context, d *ddl, dbInfo *model.DBInfo, tblI
checkHistoryJobArgs(c, ctx, job.ID, &historyJobArgs{ver: v, tbl: tblInfo})
return job
}

func init() {
logLevel := os.Getenv("log_level")
logutil.InitLogger(&logutil.LogConfig{
Level: logLevel,
})
}
8 changes: 4 additions & 4 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ import (

func TestT(t *testing.T) {
CustomVerboseFlag = true
logLevel := os.Getenv("log_level")
logutil.InitLogger(&logutil.LogConfig{
Level: logLevel,
})
TestingT(t)
}

Expand Down Expand Up @@ -89,10 +93,6 @@ func (s *testSuite) SetUpSuite(c *C) {
}
_, err := tidb.BootstrapSession(s.store)
c.Assert(err, IsNil)
logLevel := os.Getenv("log_level")
logutil.InitLogger(&logutil.LogConfig{
Level: logLevel,
})
}

func (s *testSuite) TearDownSuite(c *C) {
Expand Down
15 changes: 0 additions & 15 deletions new_session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ package tidb_test
import (
"fmt"
"math"
"os"
"sync"
"time"

. "github.com/pingcap/check"
"github.com/pingcap/pd/pkg/logutil"
"github.com/pingcap/tidb"
"github.com/pingcap/tidb/context"
"github.com/pingcap/tidb/domain"
Expand All @@ -37,17 +35,6 @@ import (
"github.com/pingcap/tidb/util/testleak"
)

var once sync.Once

func setLogLevelFromEnv() {
once.Do(func() {
logLevel := os.Getenv("log_level")
logutil.InitLogger(&logutil.LogConfig{
Level: logLevel,
})
})
}

var _ = Suite(&testSessionSuite{})

type testSessionSuite struct {
Expand All @@ -70,7 +57,6 @@ func (s *testSessionSuite) SetUpSuite(c *C) {
tidb.SetStatsLease(0)
_, err = tidb.BootstrapSession(s.store)
c.Assert(err, IsNil)
setLogLevelFromEnv()
}

func (s *testSessionSuite) TearDownTest(c *C) {
Expand Down Expand Up @@ -378,7 +364,6 @@ func (s *testSchemaSuite) SetUpSuite(c *C) {
tidb.SetStatsLease(0)
_, err = tidb.BootstrapSession(s.store)
c.Assert(err, IsNil)
setLogLevelFromEnv()
}

func (s *testSchemaSuite) TestSchemaCheckerSQL(c *C) {
Expand Down
5 changes: 5 additions & 0 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,18 @@ import (
log "github.com/Sirupsen/logrus"
"github.com/go-sql-driver/mysql"
. "github.com/pingcap/check"
"github.com/pingcap/pd/pkg/logutil"
"github.com/pingcap/tidb/executor"
tmysql "github.com/pingcap/tidb/mysql"
"github.com/pingcap/tidb/util/printer"
)

func TestT(t *testing.T) {
CustomVerboseFlag = true
logLevel := os.Getenv("log_level")
logutil.InitLogger(&logutil.LogConfig{
Level: logLevel,
})
TestingT(t)
}

Expand Down
2 changes: 0 additions & 2 deletions server/tidb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"os"
"time"

log "github.com/Sirupsen/logrus"
"github.com/go-sql-driver/mysql"
"github.com/juju/errors"
. "github.com/pingcap/check"
Expand All @@ -43,7 +42,6 @@ var suite = new(TidbTestSuite)
var _ = Suite(suite)

func (ts *TidbTestSuite) SetUpSuite(c *C) {
log.SetLevel(log.ErrorLevel)
store, err := tidb.NewStore("memory:///tmp/tidb")
c.Assert(err, IsNil)
_, err = tidb.BootstrapSession(store)
Expand Down
8 changes: 4 additions & 4 deletions sessionctx/binloginfo/binloginfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ import (

func TestT(t *testing.T) {
CustomVerboseFlag = true
logLevel := os.Getenv("log_level")
logutil.InitLogger(&logutil.LogConfig{
Level: logLevel,
})
TestingT(t)
}

Expand Down Expand Up @@ -73,10 +77,6 @@ type testBinlogSuite struct {
}

func (s *testBinlogSuite) SetUpSuite(c *C) {
logLevel := os.Getenv("log_level")
logutil.InitLogger(&logutil.LogConfig{
Level: logLevel,
})
store, err := tikv.NewMockTikvStore()
c.Assert(err, IsNil)
s.store = store
Expand Down
8 changes: 4 additions & 4 deletions store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ const (

func TestT(t *testing.T) {
CustomVerboseFlag = true
logLevel := os.Getenv("log_level")
logutil.InitLogger(&logutil.LogConfig{
Level: logLevel,
})
TestingT(t)
}

Expand All @@ -61,10 +65,6 @@ func (s *testKVSuite) SetUpSuite(c *C) {

cacheS, _ := tidb.NewStore(fmt.Sprintf("%s://%s", *testStore, *testStorePath))
c.Assert(cacheS, Equals, store)
logLevel := os.Getenv("log_level")
logutil.InitLogger(&logutil.LogConfig{
Level: logLevel,
})
}

func (s *testKVSuite) TearDownSuite(c *C) {
Expand Down

0 comments on commit 117ff28

Please sign in to comment.