Skip to content

Commit 98bbd14

Browse files
authored
test: fix part of unit tests for next-gen (#63192)
ref #61702
1 parent 032d5f8 commit 98bbd14

36 files changed

+273
-73
lines changed

br/pkg/mock/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ go_library(
2323
"//pkg/server",
2424
"//pkg/session",
2525
"//pkg/store/mockstore",
26+
"//pkg/store/mockstore/teststore",
2627
"//pkg/types",
2728
"@com_github_aws_aws_sdk_go//aws/request",
2829
"@com_github_aws_aws_sdk_go//service/s3",

br/pkg/mock/mock_cluster.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/pingcap/tidb/pkg/server"
2222
"github.com/pingcap/tidb/pkg/session"
2323
"github.com/pingcap/tidb/pkg/store/mockstore"
24+
"github.com/pingcap/tidb/pkg/store/mockstore/teststore"
2425
"github.com/tikv/client-go/v2/testutils"
2526
"github.com/tikv/client-go/v2/tikv"
2627
pd "github.com/tikv/pd/client"
@@ -61,7 +62,7 @@ func NewCluster() (*Cluster, error) {
6162
}()
6263
})
6364

64-
storage, err := mockstore.NewMockStore(
65+
storage, err := teststore.NewMockStoreWithoutBootstrap(
6566
mockstore.WithClusterInspector(func(c testutils.Cluster) {
6667
mockstore.BootstrapWithSingleStore(c)
6768
cluster.Cluster = c

pkg/ddl/db_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,9 @@ func TestCancelJobWriteConflict(t *testing.T) {
607607
}
608608

609609
func TestTxnSavepointWithDDL(t *testing.T) {
610+
if kerneltype.IsNextGen() {
611+
t.Skip("MDL is always enabled and read only in nextgen")
612+
}
610613
store := testkit.CreateMockStoreWithSchemaLease(t, dbTestLease)
611614
tk := testkit.NewTestKit(t, store)
612615
tk2 := testkit.NewTestKit(t, store)
@@ -1361,6 +1364,9 @@ func TestGetAllTableInfos(t *testing.T) {
13611364
}
13621365

13631366
func TestGetVersionFailed(t *testing.T) {
1367+
if kerneltype.IsNextGen() {
1368+
t.Skip("MDL is always enabled and read only in nextgen")
1369+
}
13641370
store := testkit.CreateMockStore(t)
13651371

13661372
tk := testkit.NewTestKit(t, store)

pkg/ddl/ddl_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
"github.com/pingcap/tidb/pkg/parser/charset"
3434
"github.com/pingcap/tidb/pkg/parser/mysql"
3535
"github.com/pingcap/tidb/pkg/parser/terror"
36-
"github.com/pingcap/tidb/pkg/store/mockstore"
3736
"github.com/pingcap/tidb/pkg/tablecodec"
3837
"github.com/pingcap/tidb/pkg/testkit/testfailpoint"
3938
"github.com/pingcap/tidb/pkg/util/dbterror"
@@ -76,12 +75,6 @@ func (s *JobSubmitter) DDLJobDoneChMap() *generic.SyncMap[int64, chan struct{}]
7675
return s.ddlJobDoneChMap
7776
}
7877

79-
func createMockStore(t *testing.T) kv.Storage {
80-
store, err := mockstore.NewMockStore()
81-
require.NoError(t, err)
82-
return store
83-
}
84-
8578
func TestGetIntervalFromPolicy(t *testing.T) {
8679
policy := []time.Duration{
8780
1 * time.Second,

pkg/ddl/multi_schema_change_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"testing"
2222

2323
"github.com/pingcap/failpoint"
24+
"github.com/pingcap/tidb/pkg/config/kerneltype"
2425
"github.com/pingcap/tidb/pkg/ddl"
2526
"github.com/pingcap/tidb/pkg/errno"
2627
"github.com/pingcap/tidb/pkg/kv"
@@ -848,6 +849,9 @@ func TestMultiSchemaChangeMDLView(t *testing.T) {
848849
}
849850

850851
func TestMultiSchemaChangeWithoutMDL(t *testing.T) {
852+
if kerneltype.IsNextGen() {
853+
t.Skip("MDL is always enabled and read only in nextgen")
854+
}
851855
store := testkit.CreateMockStore(t)
852856
tk := testkit.NewTestKit(t, store)
853857
tk.MustExec("use test")

pkg/ddl/schematracker/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ go_library(
3434
"//pkg/table/tables",
3535
"//pkg/util/collate",
3636
"//pkg/util/dbterror",
37+
"//pkg/util/logutil",
3738
"@com_github_ngaut_pools//:pools",
3839
"@com_github_pingcap_errors//:errors",
40+
"@org_uber_go_zap//:zap",
3941
],
4042
)
4143

pkg/ddl/schematracker/checker.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import (
4040
"github.com/pingcap/tidb/pkg/statistics/handle"
4141
"github.com/pingcap/tidb/pkg/store/helper"
4242
"github.com/pingcap/tidb/pkg/store/mockstore"
43+
"github.com/pingcap/tidb/pkg/util/logutil"
44+
"go.uber.org/zap"
4345
)
4446

4547
var (
@@ -573,6 +575,13 @@ func (d *Checker) DoDDLJobWrapper(ctx sessionctx.Context, jobW *ddl.JobWrapper)
573575
return de.DoDDLJobWrapper(ctx, jobW)
574576
}
575577

578+
// InitFromIS initializes the schema tracker from an InfoSchema.
579+
func (d *Checker) InitFromIS(is infoschema.InfoSchema) {
580+
if err := d.tracker.InitFromIS(is); err != nil {
581+
logutil.BgLogger().Warn("failed to init schema tracker from info schema", zap.Error(err))
582+
}
583+
}
584+
576585
type storageAndMore interface {
577586
kv.Storage
578587
kv.StorageWithPD

pkg/ddl/schematracker/info_store.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,24 @@ func NewInfoStore(lowerCaseTableNames int) *InfoStore {
4141
}
4242
}
4343

44+
// InitFromIS initializes InfoStore from an InfoSchema.
45+
func (i *InfoStore) InitFromIS(is infoschema.InfoSchema) error {
46+
ctx := context.Background()
47+
for _, db := range is.AllSchemas() {
48+
i.PutSchema(db)
49+
tbls, err := is.SchemaTableInfos(ctx, db.Name)
50+
if err != nil {
51+
return err
52+
}
53+
for _, tbl := range tbls {
54+
if err = i.PutTable(db.Name, tbl); err != nil {
55+
return err
56+
}
57+
}
58+
}
59+
return nil
60+
}
61+
4462
func (i *InfoStore) ciStr2Key(name ast.CIStr) string {
4563
if i.lowerCaseTableNames == 0 {
4664
return name.O

pkg/ddl/tests/fail/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ go_test(
1212
shard_count = 11,
1313
deps = [
1414
"//pkg/config",
15+
"//pkg/config/kerneltype",
1516
"//pkg/ddl",
1617
"//pkg/ddl/schematracker",
1718
"//pkg/ddl/schemaver",
@@ -21,6 +22,7 @@ go_test(
2122
"//pkg/session",
2223
"//pkg/sessionctx/vardef",
2324
"//pkg/store/mockstore",
25+
"//pkg/store/mockstore/teststore",
2426
"//pkg/tablecodec",
2527
"//pkg/testkit",
2628
"//pkg/testkit/testfailpoint",

pkg/ddl/tests/fail/fail_db_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"time"
2323

2424
"github.com/pingcap/failpoint"
25+
"github.com/pingcap/tidb/pkg/config/kerneltype"
2526
"github.com/pingcap/tidb/pkg/ddl/schematracker"
2627
"github.com/pingcap/tidb/pkg/ddl/schemaver"
2728
"github.com/pingcap/tidb/pkg/domain"
@@ -30,6 +31,7 @@ import (
3031
"github.com/pingcap/tidb/pkg/session"
3132
"github.com/pingcap/tidb/pkg/sessionctx/vardef"
3233
"github.com/pingcap/tidb/pkg/store/mockstore"
34+
"github.com/pingcap/tidb/pkg/store/mockstore/teststore"
3335
"github.com/pingcap/tidb/pkg/tablecodec"
3436
"github.com/pingcap/tidb/pkg/testkit"
3537
"github.com/pingcap/tidb/pkg/testkit/testfailpoint"
@@ -51,7 +53,7 @@ func createFailDBSuite(t *testing.T) (s *failedSuite) {
5153
func createFailDBSuiteWithLease(t *testing.T, lease time.Duration) (s *failedSuite) {
5254
s = new(failedSuite)
5355
var err error
54-
s.store, err = mockstore.NewMockStore(
56+
s.store, err = teststore.NewMockStoreWithoutBootstrap(
5557
mockstore.WithClusterInspector(func(c testutils.Cluster) {
5658
mockstore.BootstrapWithSingleStore(c)
5759
s.cluster = c
@@ -211,6 +213,9 @@ func TestAddIndexFailed(t *testing.T) {
211213

212214
// Split the table.
213215
tableStart := tablecodec.GenTableRecordPrefix(tblID)
216+
if kerneltype.IsNextGen() {
217+
tableStart = s.store.GetCodec().EncodeKey(tableStart)
218+
}
214219
s.cluster.SplitKeys(tableStart, tableStart.PrefixNext(), 100)
215220

216221
tk.MustExec("alter table t add index idx_b(b)")

0 commit comments

Comments
 (0)