testenv: unite all GOMAXPROCS at test (#43175)
This commit is contained in:
@ -193,6 +193,7 @@ go_test(
|
||||
"//testkit",
|
||||
"//testkit/external",
|
||||
"//testkit/testdata",
|
||||
"//testkit/testenv",
|
||||
"//testkit/testmain",
|
||||
"//testkit/testsetup",
|
||||
"//types",
|
||||
@ -203,7 +204,6 @@ go_test(
|
||||
"//util/cpuprofile",
|
||||
"//util/dbterror/exeerrors",
|
||||
"//util/deadlockhistory",
|
||||
"//util/mathutil",
|
||||
"//util/mock",
|
||||
"//util/plancodec",
|
||||
"//util/resourcegrouptag",
|
||||
|
||||
@ -26,7 +26,6 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
@ -40,7 +39,7 @@ import (
|
||||
"github.com/pingcap/tidb/kv"
|
||||
tmysql "github.com/pingcap/tidb/parser/mysql"
|
||||
"github.com/pingcap/tidb/testkit"
|
||||
"github.com/pingcap/tidb/util/mathutil"
|
||||
"github.com/pingcap/tidb/testkit/testenv"
|
||||
"github.com/pingcap/tidb/util/versioninfo"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/zap"
|
||||
@ -62,7 +61,7 @@ type testServerClient struct {
|
||||
|
||||
// newTestServerClient return a testServerClient with unique address
|
||||
func newTestServerClient() *testServerClient {
|
||||
runtime.GOMAXPROCS(mathutil.Min(8, runtime.GOMAXPROCS(0)))
|
||||
testenv.SetGOMAXPROCSForTest()
|
||||
return &testServerClient{
|
||||
port: 0,
|
||||
statusPort: 0,
|
||||
|
||||
@ -67,6 +67,7 @@ go_library(
|
||||
"//table/temptable",
|
||||
"//tablecodec",
|
||||
"//telemetry",
|
||||
"//testkit/testenv",
|
||||
"//ttl/ttlworker",
|
||||
"//types",
|
||||
"//types/parser_driver",
|
||||
|
||||
@ -16,14 +16,13 @@ package session
|
||||
|
||||
import (
|
||||
"context"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/pingcap/tidb/domain"
|
||||
"github.com/pingcap/tidb/expression"
|
||||
"github.com/pingcap/tidb/kv"
|
||||
"github.com/pingcap/tidb/store/mockstore"
|
||||
"github.com/pingcap/tidb/util/mathutil"
|
||||
"github.com/pingcap/tidb/testkit/testenv"
|
||||
"github.com/pingcap/tidb/util/sqlexec"
|
||||
"github.com/stretchr/testify/require"
|
||||
atomicutil "go.uber.org/atomic"
|
||||
@ -40,7 +39,7 @@ var (
|
||||
|
||||
// CreateStoreAndBootstrap creates a mock store and bootstrap it.
|
||||
func CreateStoreAndBootstrap(t *testing.T) (kv.Storage, *domain.Domain) {
|
||||
runtime.GOMAXPROCS(mathutil.Min(8, runtime.GOMAXPROCS(0)))
|
||||
testenv.SetGOMAXPROCSForTest()
|
||||
store, err := mockstore.NewMockStore()
|
||||
require.NoError(t, err)
|
||||
dom, err := BootstrapSession(store)
|
||||
|
||||
@ -16,6 +16,7 @@ go_library(
|
||||
"//store/mockstore/mockcopr",
|
||||
"//store/mockstore/mockstorage",
|
||||
"//store/mockstore/unistore",
|
||||
"//testkit/testenv",
|
||||
"@com_github_pingcap_errors//:errors",
|
||||
"@com_github_tikv_client_go_v2//testutils",
|
||||
"@com_github_tikv_client_go_v2//tikv",
|
||||
|
||||
@ -22,6 +22,7 @@ import (
|
||||
"github.com/pingcap/tidb/config"
|
||||
"github.com/pingcap/tidb/kv"
|
||||
"github.com/pingcap/tidb/store/mockstore/unistore"
|
||||
"github.com/pingcap/tidb/testkit/testenv"
|
||||
"github.com/tikv/client-go/v2/testutils"
|
||||
"github.com/tikv/client-go/v2/tikv"
|
||||
pd "github.com/tikv/pd/client"
|
||||
@ -163,6 +164,7 @@ var DDLCheckerInjector func(kv.Storage) kv.Storage
|
||||
// NewMockStore creates a mocked tikv store, the path is the file path to store the data.
|
||||
// If path is an empty string, a memory storage will be created.
|
||||
func NewMockStore(options ...MockTiKVStoreOption) (kv.Storage, error) {
|
||||
testenv.SetGOMAXPROCSForTest()
|
||||
opt := mockOptions{
|
||||
clusterInspector: func(c testutils.Cluster) {
|
||||
BootstrapWithSingleStore(c)
|
||||
|
||||
@ -28,12 +28,12 @@ go_library(
|
||||
"//sessionctx/variable",
|
||||
"//store/driver",
|
||||
"//store/mockstore",
|
||||
"//testkit/testenv",
|
||||
"//util",
|
||||
"//util/breakpoint",
|
||||
"//util/chunk",
|
||||
"//util/gctuner",
|
||||
"//util/intest",
|
||||
"//util/mathutil",
|
||||
"//util/sqlexec",
|
||||
"@com_github_pingcap_errors//:errors",
|
||||
"@com_github_pingcap_failpoint//:failpoint",
|
||||
|
||||
9
testkit/testenv/BUILD.bazel
Normal file
9
testkit/testenv/BUILD.bazel
Normal file
@ -0,0 +1,9 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "testenv",
|
||||
srcs = ["testenv.go"],
|
||||
importpath = "github.com/pingcap/tidb/testkit/testenv",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["//util/mathutil"],
|
||||
)
|
||||
26
testkit/testenv/testenv.go
Normal file
26
testkit/testenv/testenv.go
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright 2023 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 testenv
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
|
||||
"github.com/pingcap/tidb/util/mathutil"
|
||||
)
|
||||
|
||||
// SetGOMAXPROCSForTest sets GOMAXPROCS to 8 if it is greater than 8.
|
||||
func SetGOMAXPROCSForTest() {
|
||||
runtime.GOMAXPROCS(mathutil.Min(8, runtime.GOMAXPROCS(0)))
|
||||
}
|
||||
@ -19,7 +19,6 @@ package testkit
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
@ -32,9 +31,9 @@ import (
|
||||
"github.com/pingcap/tidb/parser/terror"
|
||||
"github.com/pingcap/tidb/session"
|
||||
"github.com/pingcap/tidb/sessionctx/variable"
|
||||
"github.com/pingcap/tidb/testkit/testenv"
|
||||
"github.com/pingcap/tidb/util/chunk"
|
||||
"github.com/pingcap/tidb/util/intest"
|
||||
"github.com/pingcap/tidb/util/mathutil"
|
||||
"github.com/pingcap/tidb/util/sqlexec"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -58,7 +57,7 @@ type TestKit struct {
|
||||
// NewTestKit returns a new *TestKit.
|
||||
func NewTestKit(t testing.TB, store kv.Storage) *TestKit {
|
||||
require.True(t, intest.InTest, "you should add --tags=intest when to test, see https://pingcap.github.io/tidb-dev-guide/get-started/setup-an-ide.html for help")
|
||||
runtime.GOMAXPROCS(mathutil.Min(16, runtime.GOMAXPROCS(0)))
|
||||
testenv.SetGOMAXPROCSForTest()
|
||||
tk := &TestKit{
|
||||
require: require.New(t),
|
||||
assert: assert.New(t),
|
||||
|
||||
Reference in New Issue
Block a user