Skip to content

Commit 6eea739

Browse files
authored
testkit,store/mockstore: make store image to accelerate unit test (#42521)
close #42434
1 parent b4ba24b commit 6eea739

File tree

24 files changed

+141
-32
lines changed

24 files changed

+141
-32
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ require (
7777
github.com/nishanths/predeclared v0.2.2
7878
github.com/opentracing/basictracer-go v1.0.0
7979
github.com/opentracing/opentracing-go v1.2.0
80+
github.com/otiai10/copy v1.2.0
8081
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
8182
github.com/pingcap/badger v1.5.1-0.20230103063557-828f39b09b6d
8283
github.com/pingcap/errors v0.11.5-0.20231212100244-799fae176cfb

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJCh
688688
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
689689
github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs=
690690
github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=
691+
github.com/otiai10/mint v1.3.1 h1:BCmzIS3n71sGfHB5NMNDB3lHYPz8fWSkCAErHed//qc=
691692
github.com/otiai10/mint v1.3.1/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
692693
github.com/pborman/getopt v0.0.0-20180729010549-6fdd0a2c7117/go.mod h1:85jBQOZwpVEaDAr341tbn15RS4fCAsIst0qp7i8ex1o=
693694
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=

pkg/ddl/table_split_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
)
3232

3333
func TestTableSplit(t *testing.T) {
34-
store, err := mockstore.NewMockStore()
34+
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
3535
require.NoError(t, err)
3636
defer func() {
3737
err := store.Close()

pkg/disttask/framework/testutil/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ go_library(
2323
"//pkg/disttask/framework/taskexecutor",
2424
"//pkg/kv",
2525
"//pkg/sessionctx",
26+
"//pkg/store/mockstore",
2627
"//pkg/testkit",
2728
"//pkg/util/sqlexec",
2829
"@com_github_ngaut_pools//:pools",

pkg/disttask/framework/testutil/table_util.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/pingcap/failpoint"
2424
"github.com/pingcap/tidb/pkg/disttask/framework/storage"
2525
"github.com/pingcap/tidb/pkg/kv"
26+
"github.com/pingcap/tidb/pkg/store/mockstore"
2627
"github.com/pingcap/tidb/pkg/testkit"
2728
"github.com/stretchr/testify/require"
2829
"github.com/tikv/client-go/v2/util"
@@ -54,7 +55,7 @@ func getResourcePool(t *testing.T) (kv.Storage, *pools.ResourcePool) {
5455
defer func() {
5556
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/domain/MockDisableDistTask"))
5657
}()
57-
store := testkit.CreateMockStore(t)
58+
store := testkit.CreateMockStore(t, mockstore.WithStoreType(mockstore.EmbedUnistore))
5859
tk := testkit.NewTestKit(t, store)
5960
pool := pools.NewResourcePool(func() (pools.Resource, error) {
6061
return tk.Session(), nil

pkg/executor/recover_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/pingcap/tidb/pkg/infoschema"
2727
"github.com/pingcap/tidb/pkg/parser/auth"
2828
"github.com/pingcap/tidb/pkg/sessionctx/variable"
29+
"github.com/pingcap/tidb/pkg/store/mockstore"
2930
"github.com/pingcap/tidb/pkg/testkit"
3031
"github.com/pingcap/tidb/pkg/types"
3132
"github.com/pingcap/tidb/pkg/util/dbterror"
@@ -136,7 +137,7 @@ func TestFlashbackTable(t *testing.T) {
136137
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/meta/autoid/mockAutoIDChange"))
137138
}()
138139

139-
store := testkit.CreateMockStore(t)
140+
store := testkit.CreateMockStore(t, mockstore.WithStoreType(mockstore.EmbedUnistore))
140141

141142
tk := testkit.NewTestKit(t, store)
142143
tk.MustExec("create database if not exists test_flashback")

pkg/expression/integration_test/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ go_test(
2222
"//pkg/planner/core",
2323
"//pkg/session",
2424
"//pkg/sessionctx/variable",
25+
"//pkg/store/mockstore",
2526
"//pkg/tablecodec",
2627
"//pkg/testkit",
2728
"//pkg/testkit/testmain",

pkg/expression/integration_test/integration_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import (
4343
plannercore "github.com/pingcap/tidb/pkg/planner/core"
4444
"github.com/pingcap/tidb/pkg/session"
4545
"github.com/pingcap/tidb/pkg/sessionctx/variable"
46+
"github.com/pingcap/tidb/pkg/store/mockstore"
4647
"github.com/pingcap/tidb/pkg/tablecodec"
4748
"github.com/pingcap/tidb/pkg/testkit"
4849
"github.com/pingcap/tidb/pkg/types"
@@ -57,7 +58,7 @@ import (
5758

5859
func TestGetLock(t *testing.T) {
5960
ctx := context.Background()
60-
store := testkit.CreateMockStore(t)
61+
store := testkit.CreateMockStore(t, mockstore.WithStoreType(mockstore.EmbedUnistore))
6162
tk := testkit.NewTestKit(t, store)
6263

6364
// Increase pessimistic txn max retry count to make test more stable.

pkg/meta/autoid/autoid_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestSignedAutoid(t *testing.T) {
5353
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/meta/autoid/mockAutoIDChange"))
5454
}()
5555

56-
store, err := mockstore.NewMockStore()
56+
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
5757
require.NoError(t, err)
5858
defer func() {
5959
err := store.Close()
@@ -258,7 +258,7 @@ func TestUnsignedAutoid(t *testing.T) {
258258
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/meta/autoid/mockAutoIDChange"))
259259
}()
260260

261-
store, err := mockstore.NewMockStore()
261+
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
262262
require.NoError(t, err)
263263
defer func() {
264264
err := store.Close()
@@ -416,7 +416,7 @@ func TestUnsignedAutoid(t *testing.T) {
416416
// TestConcurrentAlloc is used for the test that
417417
// multiple allocators allocate ID with the same table ID concurrently.
418418
func TestConcurrentAlloc(t *testing.T) {
419-
store, err := mockstore.NewMockStore()
419+
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
420420
require.NoError(t, err)
421421
defer func() {
422422
err := store.Close()
@@ -507,7 +507,7 @@ func TestConcurrentAlloc(t *testing.T) {
507507
// TestRollbackAlloc tests that when the allocation transaction commit failed,
508508
// the local variable base and end doesn't change.
509509
func TestRollbackAlloc(t *testing.T) {
510-
store, err := mockstore.NewMockStore()
510+
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
511511
require.NoError(t, err)
512512
defer func() {
513513
err := store.Close()
@@ -558,7 +558,7 @@ func TestAllocComputationIssue(t *testing.T) {
558558
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/meta/autoid/mockAutoIDCustomize"))
559559
}()
560560

561-
store, err := mockstore.NewMockStore()
561+
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
562562
require.NoError(t, err)
563563
defer func() {
564564
err := store.Close()
@@ -609,7 +609,7 @@ func TestAllocComputationIssue(t *testing.T) {
609609
}
610610

611611
func TestIssue40584(t *testing.T) {
612-
store, err := mockstore.NewMockStore()
612+
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
613613
require.NoError(t, err)
614614
defer func() {
615615
err := store.Close()

pkg/meta/autoid/seq_autoid_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
)
3232

3333
func TestSequenceAutoid(t *testing.T) {
34-
store, err := mockstore.NewMockStore()
34+
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
3535
require.NoError(t, err)
3636
defer func() {
3737
err := store.Close()
@@ -156,7 +156,7 @@ func TestSequenceAutoid(t *testing.T) {
156156
}
157157

158158
func TestConcurrentAllocSequence(t *testing.T) {
159-
store, err := mockstore.NewMockStore()
159+
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
160160
require.NoError(t, err)
161161
defer func() {
162162
err := store.Close()

0 commit comments

Comments
 (0)