Skip to content

Commit

Permalink
testkit: reset the resource manager after test finishes (#40638)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkingrei authored Jan 17, 2023
1 parent bdc6f4b commit 90e7271
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions resourcemanager/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ go_library(
"//resourcemanager/util",
"//util",
"//util/cpu",
"@com_github_google_uuid//:uuid",
"@com_github_pingcap_log//:log",
"@org_uber_go_zap//:zap",
],
Expand Down
11 changes: 11 additions & 0 deletions resourcemanager/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package resourcemanager
import (
"time"

"github.com/google/uuid"
"github.com/pingcap/tidb/resourcemanager/scheduler"
"github.com/pingcap/tidb/resourcemanager/util"
tidbutil "github.com/pingcap/tidb/util"
Expand All @@ -26,6 +27,11 @@ import (
// GlobalResourceManager is a global resource manager
var GlobalResourceManager = NewResourceManger()

// RandomName is to get a random name for register pool. It is just for test.
func RandomName() string {
return uuid.New().String()
}

// ResourceManager is a resource manager
type ResourceManager struct {
poolMap *util.ShardPoolMap
Expand Down Expand Up @@ -85,3 +91,8 @@ func (r *ResourceManager) registerPool(name string, pool *util.PoolContainer) er
func (r *ResourceManager) Unregister(name string) {
r.poolMap.Del(name)
}

// Reset is to Reset resource manager. it is just for test.
func (r *ResourceManager) Reset() {
r.poolMap = util.NewShardPoolMap()
}
1 change: 1 addition & 0 deletions testkit/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ go_library(
"//parser/ast",
"//parser/terror",
"//planner/core",
"//resourcemanager",
"//session",
"//session/txninfo",
"//sessionctx/variable",
Expand Down
2 changes: 2 additions & 0 deletions testkit/mockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/pingcap/tidb/ddl/schematracker"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/resourcemanager"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/store/driver"
"github.com/pingcap/tidb/store/mockstore"
Expand Down Expand Up @@ -91,6 +92,7 @@ func bootstrap(t testing.TB, store kv.Storage, lease time.Duration) *domain.Doma
err := store.Close()
require.NoError(t, err)
view.Stop()
resourcemanager.GlobalResourceManager.Reset()
})
return dom
}
Expand Down

0 comments on commit 90e7271

Please sign in to comment.