Skip to content

Commit

Permalink
test: stabilize TestGetTargetNodeCpuCnt (pingcap#57823)
Browse files Browse the repository at this point in the history
  • Loading branch information
tangenta authored Nov 29, 2024
1 parent f6ff412 commit b9eeab4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
1 change: 1 addition & 0 deletions pkg/executor/importer/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ go_test(
"//pkg/session",
"//pkg/sessionctx/variable",
"//pkg/testkit",
"//pkg/testkit/testfailpoint",
"//pkg/testkit/testsetup",
"//pkg/types",
"//pkg/util",
Expand Down
17 changes: 7 additions & 10 deletions pkg/executor/importer/importer_testkit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (
"github.com/pingcap/tidb/pkg/session"
"github.com/pingcap/tidb/pkg/sessionctx/variable"
"github.com/pingcap/tidb/pkg/testkit"
"github.com/pingcap/tidb/pkg/testkit/testfailpoint"
"github.com/pingcap/tidb/pkg/types"
"github.com/pingcap/tidb/pkg/util/dbterror/exeerrors"
"github.com/pingcap/tidb/pkg/util/logutil"
Expand Down Expand Up @@ -159,18 +160,14 @@ func TestVerifyChecksum(t *testing.T) {
}

func TestGetTargetNodeCpuCnt(t *testing.T) {
_, tm, ctx := testutil.InitTableTest(t)
old := variable.EnableDistTask.Load()
store, tm, ctx := testutil.InitTableTest(t)
tk := testkit.NewTestKit(t, store)

variable.EnableDistTask.Store(false)
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/util/cpu/mockNumCpu", "return(16)"))
t.Cleanup(func() {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/util/cpu/mockNumCpu"))
variable.EnableDistTask.Store(old)
})
tk.MustExec("set @@global.tidb_enable_dist_task = off;")
testfailpoint.Enable(t, "github.com/pingcap/tidb/pkg/util/cpu/mockNumCpu", "return(16)")
require.NoError(t, tm.InitMeta(ctx, "tidb1", ""))

require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/util/cpu/mockNumCpu", "return(8)"))
testfailpoint.Enable(t, "github.com/pingcap/tidb/pkg/util/cpu/mockNumCpu", "return(8)")
targetNodeCPUCnt, err := importer.GetTargetNodeCPUCnt(ctx, importer.DataSourceTypeQuery, "")
require.NoError(t, err)
require.Equal(t, 8, targetNodeCPUCnt)
Expand All @@ -187,7 +184,7 @@ func TestGetTargetNodeCpuCnt(t *testing.T) {
require.NoError(t, err)
require.Equal(t, 8, targetNodeCPUCnt)
// disttask enabled
variable.EnableDistTask.Store(true)
tk.MustExec("set @@global.tidb_enable_dist_task = on;")

targetNodeCPUCnt, err = importer.GetTargetNodeCPUCnt(ctx, importer.DataSourceTypeFile, "s3://path/to/xxx.csv")
require.NoError(t, err)
Expand Down

0 comments on commit b9eeab4

Please sign in to comment.