Skip to content

Commit

Permalink
ddl/test: split realtikv addindex testutil (pingcap#49120)
Browse files Browse the repository at this point in the history
  • Loading branch information
ywqzzy authored Dec 4, 2023
1 parent 795335a commit c0affea
Show file tree
Hide file tree
Showing 10 changed files with 210 additions and 178 deletions.
23 changes: 2 additions & 21 deletions tests/realtikvtest/addindextest/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "addindextest",
srcs = [
"common.go",
"compatibility.go",
"workload.go",
],
importpath = "github.com/pingcap/tidb/tests/realtikvtest/addindextest",
visibility = ["//visibility:public"],
deps = [
"//pkg/kv",
"//pkg/testkit",
"//pkg/util/logutil",
"@com_github_pingcap_failpoint//:failpoint",
"@com_github_stretchr_testify//require",
"@org_uber_go_zap//:zap",
],
)
load("@io_bazel_rules_go//go:def.bzl", "go_test")

go_test(
name = "addindextest_test",
Expand All @@ -30,11 +11,11 @@ go_test(
"multi_schema_change_test.go",
"pitr_test.go",
],
embed = [":addindextest"],
deps = [
"//pkg/config",
"//pkg/testkit",
"//tests/realtikvtest",
"//tests/realtikvtest/addindextestutil",
"@com_github_stretchr_testify//require",
],
)
36 changes: 11 additions & 25 deletions tests/realtikvtest/addindextest/add_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/pingcap/tidb/pkg/config"
"github.com/pingcap/tidb/pkg/testkit"
"github.com/pingcap/tidb/tests/realtikvtest"
"github.com/pingcap/tidb/tests/realtikvtest/addindextestutil"
)

func init() {
Expand All @@ -28,29 +29,14 @@ func init() {
})
}

func initTest(t *testing.T) *suiteContext {
store := realtikvtest.CreateMockStoreAndSetup(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("drop database if exists addindex;")
tk.MustExec("create database addindex;")
tk.MustExec("use addindex;")
tk.MustExec(`set global tidb_ddl_enable_fast_reorg=on;`)

ctx := newSuiteContext(t, tk, store)
createTable(tk)
insertRows(tk)
initWorkloadParams(ctx)
return ctx
}

func TestCreateNonUniqueIndex(t *testing.T) {
var colIDs = [][]int{
{1, 4, 7, 10, 13, 16, 19, 22, 25},
{2, 5, 8, 11, 14, 17, 20, 23, 26},
{3, 6, 9, 12, 15, 18, 21, 24, 27},
}
ctx := initTest(t)
testOneColFrame(ctx, colIDs, addIndexNonUnique)
ctx := addindextestutil.InitTest(t)
addindextestutil.TestOneColFrame(ctx, colIDs, addindextestutil.AddIndexNonUnique)
}

func TestCreateUniqueIndex(t *testing.T) {
Expand All @@ -59,18 +45,18 @@ func TestCreateUniqueIndex(t *testing.T) {
{2, 9, 11, 17},
{3, 12, 25},
}
ctx := initTest(t)
testOneColFrame(ctx, colIDs, addIndexUnique)
ctx := addindextestutil.InitTest(t)
addindextestutil.TestOneColFrame(ctx, colIDs, addindextestutil.AddIndexUnique)
}

func TestCreatePrimaryKey(t *testing.T) {
ctx := initTest(t)
testOneIndexFrame(ctx, 0, addIndexPK)
ctx := addindextestutil.InitTest(t)
addindextestutil.TestOneIndexFrame(ctx, 0, addindextestutil.AddIndexPK)
}

func TestCreateGenColIndex(t *testing.T) {
ctx := initTest(t)
testOneIndexFrame(ctx, 29, addIndexGenCol)
ctx := addindextestutil.InitTest(t)
addindextestutil.TestOneIndexFrame(ctx, 29, addindextestutil.AddIndexGenCol)
}

func TestCreateMultiColsIndex(t *testing.T) {
Expand All @@ -97,8 +83,8 @@ func TestCreateMultiColsIndex(t *testing.T) {
{18, 21, 24, 27},
}
}
ctx := initTest(t)
testTwoColsFrame(ctx, coliIDs, coljIDs, addIndexMultiCols)
ctx := addindextestutil.InitTest(t)
addindextestutil.TestTwoColsFrame(ctx, coliIDs, coljIDs, addindextestutil.AddIndexMultiCols)
}

func TestAddForeignKeyWithAutoCreateIndex(t *testing.T) {
Expand Down
39 changes: 16 additions & 23 deletions tests/realtikvtest/addindextest/concurrent_ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,19 @@ package addindextest
import (
"testing"

"github.com/pingcap/tidb/tests/realtikvtest/addindextestutil"
"github.com/stretchr/testify/require"
)

func initConcurrentDDLTest(t *testing.T, colIIDs [][]int, colJIDs [][]int, tType testType) *suiteContext {
ctx := initCompCtx(t)
ctx.CompCtx.isConcurrentDDL = true
ctx.CompCtx.tType = tType
ctx.CompCtx.colIIDs = colIIDs
ctx.CompCtx.colJIDs = colJIDs
return ctx
}
func TestConcurrentDDLCreateNonUniqueIndex(t *testing.T) {
var colIDs = [][]int{
{1, 4, 7, 10, 13},
{14, 17, 20, 23, 26},
{3, 6, 9, 21, 24},
}
ctx := initConcurrentDDLTest(t, colIDs, nil, TestNonUnique)
ctx.CompCtx.start(ctx)
err := ctx.CompCtx.stop(ctx)
ctx := addindextestutil.InitConcurrentDDLTest(t, colIDs, nil, addindextestutil.TestNonUnique)
ctx.CompCtx.Start(ctx)
err := ctx.CompCtx.Stop(ctx)
require.NoError(t, err)
}

Expand All @@ -46,23 +39,23 @@ func TestConcurrentDDLCreateUniqueIndex(t *testing.T) {
{2, 11, 17},
{3, 19, 25},
}
ctx := initConcurrentDDLTest(t, colIDs, nil, TestUnique)
ctx.CompCtx.start(ctx)
err := ctx.CompCtx.stop(ctx)
ctx := addindextestutil.InitConcurrentDDLTest(t, colIDs, nil, addindextestutil.TestUnique)
ctx.CompCtx.Start(ctx)
err := ctx.CompCtx.Stop(ctx)
require.NoError(t, err)
}

func TestConcurrentDDLCreatePrimaryKey(t *testing.T) {
ctx := initConcurrentDDLTest(t, nil, nil, TestPK)
ctx.CompCtx.start(ctx)
err := ctx.CompCtx.stop(ctx)
ctx := addindextestutil.InitConcurrentDDLTest(t, nil, nil, addindextestutil.TestPK)
ctx.CompCtx.Start(ctx)
err := ctx.CompCtx.Stop(ctx)
require.NoError(t, err)
}

func TestConcurrentDDLCreateGenColIndex(t *testing.T) {
ctx := initConcurrentDDLTest(t, nil, nil, TestGenIndex)
ctx.CompCtx.start(ctx)
err := ctx.CompCtx.stop(ctx)
ctx := addindextestutil.InitConcurrentDDLTest(t, nil, nil, addindextestutil.TestGenIndex)
ctx.CompCtx.Start(ctx)
err := ctx.CompCtx.Stop(ctx)
require.NoError(t, err)
}

Expand All @@ -77,8 +70,8 @@ func TestConcurrentDDLCreateMultiColsIndex(t *testing.T) {
{23},
{19},
}
ctx := initConcurrentDDLTest(t, coliIDs, coljIDs, TestMultiCols)
ctx.CompCtx.start(ctx)
err := ctx.CompCtx.stop(ctx)
ctx := addindextestutil.InitConcurrentDDLTest(t, coliIDs, coljIDs, addindextestutil.TestMultiCols)
ctx.CompCtx.Start(ctx)
err := ctx.CompCtx.Stop(ctx)
require.NoError(t, err)
}
28 changes: 12 additions & 16 deletions tests/realtikvtest/addindextest/failpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@ package addindextest

import (
"testing"
)

func initTestFailpoint(t *testing.T) *suiteContext {
ctx := initTest(t)
ctx.isFailpointsTest = true
return ctx
}
"github.com/pingcap/tidb/tests/realtikvtest/addindextestutil"
)

func TestFailpointsCreateNonUniqueIndex(t *testing.T) {
if !*FullMode {
Expand All @@ -33,8 +29,8 @@ func TestFailpointsCreateNonUniqueIndex(t *testing.T) {
{2, 5, 8, 11, 14, 17, 20, 23, 26},
{3, 6, 9, 12, 15, 18, 21, 24, 27},
}
ctx := initTestFailpoint(t)
testOneColFrame(ctx, colIDs, addIndexNonUnique)
ctx := addindextestutil.InitTestFailpoint(t)
addindextestutil.TestOneColFrame(ctx, colIDs, addindextestutil.AddIndexNonUnique)
}

func TestFailpointsCreateUniqueIndex(t *testing.T) {
Expand All @@ -46,24 +42,24 @@ func TestFailpointsCreateUniqueIndex(t *testing.T) {
{2, 9, 11, 17},
{3, 12, 25},
}
ctx := initTestFailpoint(t)
testOneColFrame(ctx, colIDs, addIndexUnique)
ctx := addindextestutil.InitTestFailpoint(t)
addindextestutil.TestOneColFrame(ctx, colIDs, addindextestutil.AddIndexUnique)
}

func TestFailpointsCreatePrimaryKeyFailpoints(t *testing.T) {
if !*FullMode {
t.Skip()
}
ctx := initTest(t)
testOneIndexFrame(ctx, 0, addIndexPK)
ctx := addindextestutil.InitTest(t)
addindextestutil.TestOneIndexFrame(ctx, 0, addindextestutil.AddIndexPK)
}

func TestFailpointsCreateGenColIndex(t *testing.T) {
if !*FullMode {
t.Skip()
}
ctx := initTestFailpoint(t)
testOneIndexFrame(ctx, 29, addIndexGenCol)
ctx := addindextestutil.InitTestFailpoint(t)
addindextestutil.TestOneIndexFrame(ctx, 29, addindextestutil.AddIndexGenCol)
}

func TestFailpointsCreateMultiColsIndex(t *testing.T) {
Expand All @@ -80,6 +76,6 @@ func TestFailpointsCreateMultiColsIndex(t *testing.T) {
{14, 17, 20},
{18, 21, 24},
}
ctx := initTestFailpoint(t)
testTwoColsFrame(ctx, coliIDs, coljIDs, addIndexMultiCols)
ctx := addindextestutil.InitTestFailpoint(t)
addindextestutil.TestTwoColsFrame(ctx, coliIDs, coljIDs, addindextestutil.AddIndexMultiCols)
}
37 changes: 17 additions & 20 deletions tests/realtikvtest/addindextest/multi_schema_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,19 @@ package addindextest

import (
"testing"

"github.com/pingcap/tidb/tests/realtikvtest/addindextestutil"
)

func initCompCtx(t *testing.T) *suiteContext {
ctx := initTest(t)
initCompCtxParams(ctx)
return ctx
}
func TestMultiSchemaChangeCreateNonUniqueIndex(t *testing.T) {
var colIDs = [][]int{
{1, 4, 7},
{2, 5, 8},
{3, 6, 9},
}
ctx := initCompCtx(t)
ctx.CompCtx.isMultiSchemaChange = true
testOneColFrame(ctx, colIDs, addIndexNonUnique)
ctx := addindextestutil.InitCompCtx(t)
ctx.CompCtx.IsMultiSchemaChange = true
addindextestutil.TestOneColFrame(ctx, colIDs, addindextestutil.AddIndexNonUnique)
}

func TestMultiSchemaChangeCreateUniqueIndex(t *testing.T) {
Expand All @@ -40,21 +37,21 @@ func TestMultiSchemaChangeCreateUniqueIndex(t *testing.T) {
{2, 19},
{11},
}
ctx := initCompCtx(t)
ctx.CompCtx.isMultiSchemaChange = true
testOneColFrame(ctx, colIDs, addIndexUnique)
ctx := addindextestutil.InitCompCtx(t)
ctx.CompCtx.IsMultiSchemaChange = true
addindextestutil.TestOneColFrame(ctx, colIDs, addindextestutil.AddIndexUnique)
}

func TestMultiSchemaChangeCreatePrimaryKey(t *testing.T) {
ctx := initCompCtx(t)
ctx.CompCtx.isMultiSchemaChange = true
testOneIndexFrame(ctx, 0, addIndexPK)
ctx := addindextestutil.InitCompCtx(t)
ctx.CompCtx.IsMultiSchemaChange = true
addindextestutil.TestOneIndexFrame(ctx, 0, addindextestutil.AddIndexPK)
}

func TestMultiSchemaChangeCreateGenColIndex(t *testing.T) {
ctx := initCompCtx(t)
ctx.CompCtx.isMultiSchemaChange = true
testOneIndexFrame(ctx, 29, addIndexGenCol)
ctx := addindextestutil.InitCompCtx(t)
ctx.CompCtx.IsMultiSchemaChange = true
addindextestutil.TestOneIndexFrame(ctx, 29, addindextestutil.AddIndexGenCol)
}

func TestMultiSchemaChangeMultiColsIndex(t *testing.T) {
Expand All @@ -68,7 +65,7 @@ func TestMultiSchemaChangeMultiColsIndex(t *testing.T) {
{14},
{18},
}
ctx := initCompCtx(t)
ctx.CompCtx.isMultiSchemaChange = true
testTwoColsFrame(ctx, coliIDs, coljIDs, addIndexMultiCols)
ctx := addindextestutil.InitCompCtx(t)
ctx.CompCtx.IsMultiSchemaChange = true
addindextestutil.TestTwoColsFrame(ctx, coliIDs, coljIDs, addindextestutil.AddIndexMultiCols)
}
36 changes: 20 additions & 16 deletions tests/realtikvtest/addindextest/pitr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,21 @@

package addindextest

import "testing"
import (
"testing"

"github.com/pingcap/tidb/tests/realtikvtest/addindextestutil"
)

func TestPiTRCreateNonUniqueIndex(t *testing.T) {
var colIDs = [][]int{
{1, 4, 7},
{2, 5, 8},
{3, 6, 9},
}
ctx := initCompCtx(t)
ctx.CompCtx.isPiTR = true
testOneColFrame(ctx, colIDs, addIndexNonUnique)
ctx := addindextestutil.InitCompCtx(t)
ctx.CompCtx.IsPiTR = true
addindextestutil.TestOneColFrame(ctx, colIDs, addindextestutil.AddIndexNonUnique)
}

func TestPiTRCreateUniqueIndex(t *testing.T) {
Expand All @@ -33,21 +37,21 @@ func TestPiTRCreateUniqueIndex(t *testing.T) {
{11},
{19},
}
ctx := initCompCtx(t)
ctx.CompCtx.isPiTR = true
testOneColFrame(ctx, colIDs, addIndexUnique)
ctx := addindextestutil.InitCompCtx(t)
ctx.CompCtx.IsPiTR = true
addindextestutil.TestOneColFrame(ctx, colIDs, addindextestutil.AddIndexUnique)
}

func TestPiTRCreatePrimaryKey(t *testing.T) {
ctx := initCompCtx(t)
ctx.CompCtx.isPiTR = true
testOneIndexFrame(ctx, 0, addIndexPK)
ctx := addindextestutil.InitCompCtx(t)
ctx.CompCtx.IsPiTR = true
addindextestutil.TestOneIndexFrame(ctx, 0, addindextestutil.AddIndexPK)
}

func TestPiTRCreateGenColIndex(t *testing.T) {
ctx := initCompCtx(t)
ctx.CompCtx.isPiTR = true
testOneIndexFrame(ctx, 29, addIndexGenCol)
ctx := addindextestutil.InitCompCtx(t)
ctx.CompCtx.IsPiTR = true
addindextestutil.TestOneIndexFrame(ctx, 29, addindextestutil.AddIndexGenCol)
}

func TestPiTRCreateMultiColsIndex(t *testing.T) {
Expand All @@ -61,7 +65,7 @@ func TestPiTRCreateMultiColsIndex(t *testing.T) {
{23},
{27},
}
ctx := initCompCtx(t)
ctx.CompCtx.isPiTR = true
testTwoColsFrame(ctx, coliIDs, coljIDs, addIndexMultiCols)
ctx := addindextestutil.InitCompCtx(t)
ctx.CompCtx.IsPiTR = true
addindextestutil.TestTwoColsFrame(ctx, coliIDs, coljIDs, addindextestutil.AddIndexMultiCols)
}
Loading

0 comments on commit c0affea

Please sign in to comment.