MCPcopy
hub / github.com/pingcap/tidb / NewTestKit

Function NewTestKit

pkg/testkit/testkit.go:77–109  ·  view source on GitHub ↗

NewTestKit returns a new *TestKit.

(t testing.TB, store kv.Storage)

Source from the content-addressed store, hash-verified

75
76// NewTestKit returns a new *TestKit.
77func NewTestKit(t testing.TB, store kv.Storage) *TestKit {
78 if _, ok := t.(*testing.B); !ok {
79 // Don't check `intest.InTest` for benchmark. We should allow to run benchmarks without `intest` tag, because some assert may have significant performance
80 // impact.
81 require.True(t, intest.InTest && intest.EnableAssert, "you should add --tags=intest when to test, see https://pingcap.github.io/tidb-dev-guide/get-started/setup-an-ide.html for help")
82 }
83 testenv.SetGOMAXPROCSForTest()
84 tk := &TestKit{
85 require: require.New(t),
86 assert: assert.New(t),
87 t: t,
88 store: store,
89 alloc: chunk.NewAllocator(),
90 }
91 tk.RefreshSession()
92
93 dom, _ := session.GetDomain(store)
94 sm := dom.InfoSyncer().GetSessionManager()
95 if sm != nil {
96 mockSm, ok := sm.(*MockSessionManager)
97 if ok {
98 mockSm.mu.Lock()
99 if mockSm.Conn == nil {
100 mockSm.Conn = make(map[uint64]sessiontypes.Session)
101 }
102 mockSm.Conn[tk.session.GetSessionVars().ConnectionID] = tk.session
103 mockSm.mu.Unlock()
104 }
105 tk.session.SetSessionManager(sm)
106 }
107
108 return tk
109}
110
111// NewTestKitWithSession returns a new *TestKit.
112func NewTestKitWithSession(t testing.TB, store kv.Storage, se sessiontypes.Session) *TestKit {

Calls 11

RefreshSessionMethod · 0.95
SetGOMAXPROCSForTestFunction · 0.92
NewAllocatorFunction · 0.92
GetDomainFunction · 0.92
InfoSyncerMethod · 0.80
NewMethod · 0.65
GetSessionManagerMethod · 0.65
LockMethod · 0.65
GetSessionVarsMethod · 0.65
UnlockMethod · 0.65
SetSessionManagerMethod · 0.65