forked from pingcap/tidb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
82 lines (71 loc) · 3.31 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// 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 server
import (
"fmt"
"os"
"reflect"
"testing"
"github.com/pingcap/tidb/pkg/config"
"github.com/pingcap/tidb/pkg/metrics"
"github.com/pingcap/tidb/pkg/store/mockstore/unistore"
"github.com/pingcap/tidb/pkg/testkit/testdata"
"github.com/pingcap/tidb/pkg/testkit/testmain"
"github.com/pingcap/tidb/pkg/testkit/testsetup"
topsqlstate "github.com/pingcap/tidb/pkg/util/topsql/state"
"github.com/tikv/client-go/v2/tikv"
"go.uber.org/goleak"
)
var testDataMap = make(testdata.BookKeeper, 1)
func TestMain(m *testing.M) {
testsetup.SetupForCommonTest()
RunInGoTest = true // flag for NewServer to known it is running in test environment
// Enable TopSQL for all test, and check the resource tag for each RPC request.
// This is used to detect which codes are not tracked by TopSQL.
topsqlstate.EnableTopSQL()
unistore.CheckResourceTagForTopSQLInGoTest = true
tikv.EnableFailpoints()
metrics.RegisterMetrics()
// sanity check: the global config should not be changed by other pkg init function.
// see also https://github.com/pingcap/tidb/issues/22162
defaultConfig := config.NewConfig()
globalConfig := config.GetGlobalConfig()
if !reflect.DeepEqual(defaultConfig, globalConfig) {
_, _ = fmt.Fprintf(os.Stderr, "server: the global config has been changed.\n")
_, _ = fmt.Fprintf(os.Stderr, "default: %#v\nglobal: %#v", defaultConfig, globalConfig)
}
testDataMap.LoadTestSuiteData("testdata", "optimizer_suite")
opts := []goleak.Option{
goleak.IgnoreTopFunction("github.com/dgraph-io/ristretto.(*defaultPolicy).processItems"),
goleak.IgnoreTopFunction("github.com/dgraph-io/ristretto.(*Cache).processItems"),
goleak.IgnoreTopFunction("github.com/golang/glog.(*fileSink).flushDaemon"),
goleak.IgnoreTopFunction("github.com/bazelbuild/rules_go/go/tools/bzltestutil.RegisterTimeoutHandler.func1"),
goleak.IgnoreTopFunction("github.com/lestrrat-go/httprc.runFetchWorker"),
goleak.IgnoreTopFunction("time.Sleep"),
goleak.IgnoreTopFunction("database/sql.(*Tx).awaitDone"),
goleak.IgnoreTopFunction("internal/poll.runtime_pollWait"),
goleak.IgnoreTopFunction("net/http.(*persistConn).readLoop"),
goleak.IgnoreTopFunction("net/http.(*persistConn).writeLoop"),
goleak.IgnoreTopFunction("github.com/pingcap/tidb/pkg/server.NewServer.func1"),
goleak.IgnoreTopFunction("gopkg.in/natefinch/lumberjack%2ev2.(*Logger).millRun"),
goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"),
goleak.IgnoreTopFunction("go.etcd.io/etcd/client/pkg/v3/logutil.(*MergeLogger).outputLoop"),
goleak.IgnoreTopFunction("github.com/go-sql-driver/mysql.(*mysqlConn).startWatcher.func1"),
}
callback := func(i int) int {
testDataMap.GenerateOutputIfNeeded()
return i
}
goleak.VerifyTestMain(testmain.WrapTestingM(m, callback), opts...)
}