NewTestKit returns a new *TestKit.
(t testing.TB, store kv.Storage)
| 75 | |
| 76 | // NewTestKit returns a new *TestKit. |
| 77 | func 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. |
| 112 | func NewTestKitWithSession(t testing.TB, store kv.Storage, se sessiontypes.Session) *TestKit { |