Skip to content

Commit

Permalink
ddltest: refactor logutil.InitLogger in ddltest to avoid data race (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkingrei authored Dec 1, 2021
1 parent 7c5e854 commit e97e8c0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
6 changes: 1 addition & 5 deletions cmd/ddltest/ddl_serial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
_ "github.com/go-sql-driver/mysql"
"github.com/pingcap/errors"
"github.com/pingcap/log"
zaplog "github.com/pingcap/log"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/kv"
Expand All @@ -48,7 +47,6 @@ import (
"github.com/pingcap/tidb/table/tables"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/logutil"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
goctx "golang.org/x/net/context"
Expand Down Expand Up @@ -91,11 +89,9 @@ type ddlSuite struct {
}

func createDDLSuite(t *testing.T) (s *ddlSuite) {
var err error
s = new(ddlSuite)

err := logutil.InitLogger(&logutil.LogConfig{Config: zaplog.Config{Level: *logLevel}})
require.NoError(t, err)

s.quit = make(chan struct{})

s.store, err = store.New(fmt.Sprintf("tikv://%s%s", *etcd, *tikvPath))
Expand Down
36 changes: 36 additions & 0 deletions cmd/ddltest/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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 ddltest

import (
"fmt"
"os"
"testing"

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

func TestMain(m *testing.M) {
testbridge.WorkaroundGoCheckFlags()
err := logutil.InitLogger(&logutil.LogConfig{Config: zaplog.Config{Level: *logLevel}})
if err != nil {
fmt.Fprint(os.Stderr, err.Error())
os.Exit(1)
}
goleak.VerifyTestMain(m)
}

0 comments on commit e97e8c0

Please sign in to comment.