Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testkit,store/mockstore: make store image to accelerate unit test #42521

Merged
merged 27 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
105426b
testkit,store/mockstore: make store image to accelerate unit test
tiancaiamao Mar 23, 2023
39220a9
tiny clean up
tiancaiamao Mar 23, 2023
70ac665
fix build
tiancaiamao Mar 23, 2023
8b5973f
fix build
tiancaiamao Mar 23, 2023
d0c02d2
fix CI
tiancaiamao Mar 24, 2023
550eeb3
Merge branch 'master' into issue-42434
tiancaiamao Mar 29, 2023
d8e303e
fix some test cases
tiancaiamao Mar 31, 2023
ce31edd
make bazel_prepare
tiancaiamao Mar 31, 2023
e9ef16d
Merge branch 'master' into issue-42434
tiancaiamao Apr 3, 2023
b889d02
fix test
tiancaiamao Apr 3, 2023
6e83733
Merge branch 'master' into issue-42434
tiancaiamao Apr 13, 2023
8582e48
Merge branch 'master' into issue-42434
tiancaiamao Apr 19, 2023
17f37ef
Merge branch 'master' into issue-42434
tiancaiamao Apr 19, 2023
4b1007f
Merge branch 'master' into issue-42434
tiancaiamao Apr 20, 2023
747eebe
Merge branch 'master' into issue-42434
tiancaiamao Jun 12, 2023
12e8756
resolve conflict
tiancaiamao Jun 12, 2023
a2d5f26
Merge branch 'master' into issue-42434
tiancaiamao Sep 4, 2023
7870d6b
make bazel_prepare
tiancaiamao Sep 4, 2023
54679f0
make fmt
tiancaiamao Sep 4, 2023
d8ad393
Merge branch 'master' into issue-42434
tiancaiamao Dec 31, 2023
fe94751
fix build
tiancaiamao Jan 1, 2024
6e6239a
resolve confict
tiancaiamao Jan 2, 2024
b2a94fd
Merge branch 'master' into issue-42434
tiancaiamao Jan 3, 2024
943064a
fix ci
tiancaiamao Jan 3, 2024
dd443a7
fix CI
tiancaiamao Jan 3, 2024
cce19c4
fix build
tiancaiamao Jan 3, 2024
52ecfbb
Merge branch 'master' into issue-42434
tiancaiamao Jan 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ require (
github.com/nishanths/predeclared v0.2.2
github.com/opentracing/basictracer-go v1.0.0
github.com/opentracing/opentracing-go v1.2.0
github.com/otiai10/copy v1.2.0
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
github.com/pingcap/badger v1.5.1-0.20230103063557-828f39b09b6d
github.com/pingcap/errors v0.11.5-0.20231212100244-799fae176cfb
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJCh
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs=
github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=
github.com/otiai10/mint v1.3.1 h1:BCmzIS3n71sGfHB5NMNDB3lHYPz8fWSkCAErHed//qc=
github.com/otiai10/mint v1.3.1/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
github.com/pborman/getopt v0.0.0-20180729010549-6fdd0a2c7117/go.mod h1:85jBQOZwpVEaDAr341tbn15RS4fCAsIst0qp7i8ex1o=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
Expand Down
2 changes: 1 addition & 1 deletion pkg/ddl/table_split_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

func TestTableSplit(t *testing.T) {
store, err := mockstore.NewMockStore()
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
require.NoError(t, err)
defer func() {
err := store.Close()
Expand Down
1 change: 1 addition & 0 deletions pkg/disttask/framework/testutil/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ go_library(
"//pkg/disttask/framework/taskexecutor",
"//pkg/kv",
"//pkg/sessionctx",
"//pkg/store/mockstore",
"//pkg/testkit",
"//pkg/util/sqlexec",
"@com_github_ngaut_pools//:pools",
Expand Down
3 changes: 2 additions & 1 deletion pkg/disttask/framework/testutil/table_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/pkg/disttask/framework/storage"
"github.com/pingcap/tidb/pkg/kv"
"github.com/pingcap/tidb/pkg/store/mockstore"
"github.com/pingcap/tidb/pkg/testkit"
"github.com/stretchr/testify/require"
"github.com/tikv/client-go/v2/util"
Expand Down Expand Up @@ -54,7 +55,7 @@ func getResourcePool(t *testing.T) (kv.Storage, *pools.ResourcePool) {
defer func() {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/domain/MockDisableDistTask"))
}()
store := testkit.CreateMockStore(t)
store := testkit.CreateMockStore(t, mockstore.WithStoreType(mockstore.EmbedUnistore))
tk := testkit.NewTestKit(t, store)
pool := pools.NewResourcePool(func() (pools.Resource, error) {
return tk.Session(), nil
Expand Down
3 changes: 2 additions & 1 deletion pkg/executor/recover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/pingcap/tidb/pkg/infoschema"
"github.com/pingcap/tidb/pkg/parser/auth"
"github.com/pingcap/tidb/pkg/sessionctx/variable"
"github.com/pingcap/tidb/pkg/store/mockstore"
"github.com/pingcap/tidb/pkg/testkit"
"github.com/pingcap/tidb/pkg/types"
"github.com/pingcap/tidb/pkg/util/dbterror"
Expand Down Expand Up @@ -136,7 +137,7 @@ func TestFlashbackTable(t *testing.T) {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/meta/autoid/mockAutoIDChange"))
}()

store := testkit.CreateMockStore(t)
store := testkit.CreateMockStore(t, mockstore.WithStoreType(mockstore.EmbedUnistore))

tk := testkit.NewTestKit(t, store)
tk.MustExec("create database if not exists test_flashback")
Expand Down
1 change: 1 addition & 0 deletions pkg/expression/integration_test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ go_test(
"//pkg/planner/core",
"//pkg/session",
"//pkg/sessionctx/variable",
"//pkg/store/mockstore",
"//pkg/tablecodec",
"//pkg/testkit",
"//pkg/testkit/testmain",
Expand Down
3 changes: 2 additions & 1 deletion pkg/expression/integration_test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
plannercore "github.com/pingcap/tidb/pkg/planner/core"
"github.com/pingcap/tidb/pkg/session"
"github.com/pingcap/tidb/pkg/sessionctx/variable"
"github.com/pingcap/tidb/pkg/store/mockstore"
"github.com/pingcap/tidb/pkg/tablecodec"
"github.com/pingcap/tidb/pkg/testkit"
"github.com/pingcap/tidb/pkg/types"
Expand All @@ -57,7 +58,7 @@ import (

func TestGetLock(t *testing.T) {
ctx := context.Background()
store := testkit.CreateMockStore(t)
store := testkit.CreateMockStore(t, mockstore.WithStoreType(mockstore.EmbedUnistore))
tk := testkit.NewTestKit(t, store)

// Increase pessimistic txn max retry count to make test more stable.
Expand Down
12 changes: 6 additions & 6 deletions pkg/meta/autoid/autoid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestSignedAutoid(t *testing.T) {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/meta/autoid/mockAutoIDChange"))
}()

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

store, err := mockstore.NewMockStore()
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
require.NoError(t, err)
defer func() {
err := store.Close()
Expand Down Expand Up @@ -416,7 +416,7 @@ func TestUnsignedAutoid(t *testing.T) {
// TestConcurrentAlloc is used for the test that
// multiple allocators allocate ID with the same table ID concurrently.
func TestConcurrentAlloc(t *testing.T) {
store, err := mockstore.NewMockStore()
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
require.NoError(t, err)
defer func() {
err := store.Close()
Expand Down Expand Up @@ -507,7 +507,7 @@ func TestConcurrentAlloc(t *testing.T) {
// TestRollbackAlloc tests that when the allocation transaction commit failed,
// the local variable base and end doesn't change.
func TestRollbackAlloc(t *testing.T) {
store, err := mockstore.NewMockStore()
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
require.NoError(t, err)
defer func() {
err := store.Close()
Expand Down Expand Up @@ -558,7 +558,7 @@ func TestAllocComputationIssue(t *testing.T) {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/meta/autoid/mockAutoIDCustomize"))
}()

store, err := mockstore.NewMockStore()
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
require.NoError(t, err)
defer func() {
err := store.Close()
Expand Down Expand Up @@ -609,7 +609,7 @@ func TestAllocComputationIssue(t *testing.T) {
}

func TestIssue40584(t *testing.T) {
store, err := mockstore.NewMockStore()
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
require.NoError(t, err)
defer func() {
err := store.Close()
Expand Down
4 changes: 2 additions & 2 deletions pkg/meta/autoid/seq_autoid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

func TestSequenceAutoid(t *testing.T) {
store, err := mockstore.NewMockStore()
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
require.NoError(t, err)
defer func() {
err := store.Close()
Expand Down Expand Up @@ -156,7 +156,7 @@ func TestSequenceAutoid(t *testing.T) {
}

func TestConcurrentAllocSequence(t *testing.T) {
store, err := mockstore.NewMockStore()
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
require.NoError(t, err)
defer func() {
err := store.Close()
Expand Down
8 changes: 4 additions & 4 deletions pkg/meta/meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
)

func TestPlacementPolicy(t *testing.T) {
store, err := mockstore.NewMockStore()
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
require.NoError(t, err)

defer func() {
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestResourceGroup(t *testing.T) {
}

func TestMeta(t *testing.T) {
store, err := mockstore.NewMockStore()
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
require.NoError(t, err)

defer func() {
Expand Down Expand Up @@ -432,7 +432,7 @@ func TestMeta(t *testing.T) {
}

func TestSnapshot(t *testing.T) {
store, err := mockstore.NewMockStore()
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
require.NoError(t, err)
defer func() {
err := store.Close()
Expand Down Expand Up @@ -494,7 +494,7 @@ func TestElement(t *testing.T) {
}

func BenchmarkGenGlobalIDs(b *testing.B) {
store, err := mockstore.NewMockStore()
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
require.NoError(b, err)
defer func() {
err := store.Close()
Expand Down
8 changes: 4 additions & 4 deletions pkg/session/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func globalVarsCount() int64 {
// We should make sure that the following session could finish the bootstrap process.
func TestBootstrapWithError(t *testing.T) {
ctx := context.Background()
store, err := mockstore.NewMockStore()
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
require.NoError(t, err)
defer func() {
require.NoError(t, store.Close())
Expand Down Expand Up @@ -713,7 +713,7 @@ func TestAnalyzeVersionUpgradeFrom300To500(t *testing.T) {
}

func TestIndexMergeInNewCluster(t *testing.T) {
store, err := mockstore.NewMockStore()
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
require.NoError(t, err)
// Indicates we are in a new cluster.
require.Equal(t, int64(notBootstrapped), getStoreBootstrapVersion(store))
Expand Down Expand Up @@ -1033,7 +1033,7 @@ func TestTiDBOptAdvancedJoinHintWhenUpgrading(t *testing.T) {
}

func TestTiDBOptAdvancedJoinHintInNewCluster(t *testing.T) {
store, err := mockstore.NewMockStore()
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
require.NoError(t, err)
// Indicates we are in a new cluster.
require.Equal(t, int64(notBootstrapped), getStoreBootstrapVersion(store))
Expand All @@ -1059,7 +1059,7 @@ func TestTiDBOptAdvancedJoinHintInNewCluster(t *testing.T) {
}

func TestTiDBCostModelInNewCluster(t *testing.T) {
store, err := mockstore.NewMockStore()
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
require.NoError(t, err)
// Indicates we are in a new cluster.
require.Equal(t, int64(notBootstrapped), getStoreBootstrapVersion(store))
Expand Down
1 change: 1 addition & 0 deletions pkg/session/test/meta/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ go_test(
"//pkg/ddl",
"//pkg/metrics",
"//pkg/session",
"//pkg/store/mockstore",
"//pkg/tablecodec",
"//pkg/testkit",
"//pkg/testkit/external",
Expand Down
3 changes: 2 additions & 1 deletion pkg/session/test/meta/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/pingcap/tidb/pkg/ddl"
"github.com/pingcap/tidb/pkg/metrics"
"github.com/pingcap/tidb/pkg/session"
"github.com/pingcap/tidb/pkg/store/mockstore"
"github.com/pingcap/tidb/pkg/tablecodec"
"github.com/pingcap/tidb/pkg/testkit"
"github.com/pingcap/tidb/pkg/testkit/external"
Expand Down Expand Up @@ -71,7 +72,7 @@ func TestMetaTableRegion(t *testing.T) {
enableSplitTableRegionVal := atomic.LoadUint32(&ddl.EnableSplitTableRegion)
atomic.StoreUint32(&ddl.EnableSplitTableRegion, 1)
defer atomic.StoreUint32(&ddl.EnableSplitTableRegion, enableSplitTableRegionVal)
store := testkit.CreateMockStore(t)
store := testkit.CreateMockStore(t, mockstore.WithStoreType(mockstore.EmbedUnistore))

tk := testkit.NewTestKit(t, store)

Expand Down
10 changes: 5 additions & 5 deletions pkg/session/test/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ func TestRequestSource(t *testing.T) {

func TestEmptyInitSQLFile(t *testing.T) {
// A non-existent sql file would stop the bootstrap of the tidb cluster
store, err := mockstore.NewMockStore()
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
require.NoError(t, err)
config.GetGlobalConfig().InitializeSQLFile = "non-existent.sql"
defer func() {
Expand Down Expand Up @@ -832,7 +832,7 @@ func TestInitSystemVariable(t *testing.T) {

// Create a mock store
// Set the config parameter for initialize sql file
store, err := mockstore.NewMockStore()
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
require.NoError(t, err)
config.GetGlobalConfig().InitializeSQLFile = initializeSQLFile.Name()
defer func() {
Expand Down Expand Up @@ -921,7 +921,7 @@ DROP USER root;
_, err = sqlFiles[1].WriteString("drop user cloud_admin;")
require.NoError(t, err)

store, err := mockstore.NewMockStore()
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
require.NoError(t, err)
config.GetGlobalConfig().InitializeSQLFile = sqlFiles[0].Name()
defer func() {
Expand Down Expand Up @@ -999,7 +999,7 @@ insert into test.t values ("abc"); -- invalid statement
`)
require.NoError(t, err)

store, err := mockstore.NewMockStore()
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
require.NoError(t, err)
config.GetGlobalConfig().InitializeSQLFile = sqlFiles[0].Name()
defer func() {
Expand All @@ -1015,7 +1015,7 @@ insert into test.t values ("abc"); -- invalid statement
session.DisableRunBootstrapSQLFileInTest()

// Bootstrap with the second sql file, which would not been executed.
store, err = mockstore.NewMockStore()
store, err = mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
require.NoError(t, err)
defer func() {
require.NoError(t, store.Close())
Expand Down
2 changes: 1 addition & 1 deletion pkg/session/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var (
// CreateStoreAndBootstrap creates a mock store and bootstrap it.
func CreateStoreAndBootstrap(t *testing.T) (kv.Storage, *domain.Domain) {
testenv.SetGOMAXPROCSForTest()
store, err := mockstore.NewMockStore()
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.EmbedUnistore))
require.NoError(t, err)
dom, err := BootstrapSession(store)
require.NoError(t, err)
Expand Down
1 change: 1 addition & 0 deletions pkg/sessiontxn/staleread/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ go_test(
"//pkg/parser/auth",
"//pkg/sessionctx",
"//pkg/sessiontxn",
"//pkg/store/mockstore",
"//pkg/table/temptable",
"//pkg/testkit",
"//pkg/testkit/testsetup",
Expand Down
5 changes: 3 additions & 2 deletions pkg/sessiontxn/staleread/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pingcap/tidb/pkg/sessionctx"
"github.com/pingcap/tidb/pkg/sessiontxn/staleread"
"github.com/pingcap/tidb/pkg/store/mockstore"
"github.com/pingcap/tidb/pkg/table/temptable"
"github.com/pingcap/tidb/pkg/testkit"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -103,7 +104,7 @@ func getCurrentExternalTimestamp(t *testing.T, tk *testkit.TestKit) uint64 {
}

func TestStaleReadProcessorWithSelectTable(t *testing.T) {
store := testkit.CreateMockStore(t)
store := testkit.CreateMockStore(t, mockstore.WithStoreType(mockstore.EmbedUnistore))
tk := testkit.NewTestKit(t, store)
tn := astTableWithAsOf(t, "")
p1 := genStaleReadPoint(t, tk)
Expand Down Expand Up @@ -229,7 +230,7 @@ func TestStaleReadProcessorWithSelectTable(t *testing.T) {
}

func TestStaleReadProcessorWithExecutePreparedStmt(t *testing.T) {
store := testkit.CreateMockStore(t)
store := testkit.CreateMockStore(t, mockstore.WithStoreType(mockstore.EmbedUnistore))
tk := testkit.NewTestKit(t, store)
p1 := genStaleReadPoint(t, tk)
//p2 := genStaleReadPoint(t, tk)
Expand Down
1 change: 1 addition & 0 deletions pkg/store/mockstore/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ go_library(
"//pkg/store/mockstore/mockstorage",
"//pkg/store/mockstore/unistore",
"//pkg/testkit/testenv",
"@com_github_otiai10_copy//:copy",
"@com_github_pingcap_errors//:errors",
"@com_github_tikv_client_go_v2//testutils",
"@com_github_tikv_client_go_v2//tikv",
Expand Down
Loading