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

tests, ddl: move IT in ddl/ to tests/integrationtest (Part 3) #47553

Merged
merged 6 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
28 changes: 0 additions & 28 deletions ddl/ddl_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (

"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/errno"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/testkit"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -181,30 +180,3 @@ func TestCreateDatabaseError(t *testing.T) {
tk.MustExec("create database db1;")
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/ddl/mockModifyJobSchemaId"))
}

func TestRenameViewOverDifferentSchemaError(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)

//init
tk.MustExec("use test")
tk.MustExec("drop database if exists test_2;")
tk.MustExec("drop table if exists table_1;")
tk.MustExec("drop view if exists view_1;")

tk.MustExec("create database test_2;")
tk.MustExec("create table table_1 (a int);")
tk.MustExec("create view view_1 as select a from table_1;")

//different schema
tk.MustGetErrCode("rename table test.view_1 to test_2.view_1;", errno.ErrForbidSchemaChange)
tk.MustGetErrMsg("rename table test.view_1 to test_2.view_1;",
infoschema.ErrForbidSchemaChange.GenWithStackByArgs("test", "test_2").Error(),
)
tk.MustGetErrMsg("rename table test.view_1 to test_2.view_1;",
"[schema:1450]Changing schema from 'test' to 'test_2' is not allowed.",
)

//same schema
tk.MustExec("rename table test.view_1 to test.view_1000;")
}
2 changes: 0 additions & 2 deletions ddl/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ import (
"github.com/stretchr/testify/require"
)

const testLease = 5 * time.Millisecond

// DDLForTest exports for testing.
type DDLForTest interface {
// SetInterceptor sets the interceptor.
Expand Down
43 changes: 0 additions & 43 deletions ddl/index_modify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/pingcap/tidb/ddl"
testddlutil "github.com/pingcap/tidb/ddl/testutil"
"github.com/pingcap/tidb/errno"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/sessionctx"
Expand Down Expand Up @@ -985,48 +984,6 @@ LOOP:
tk.MustExec("drop table test_drop_index")
}

func TestAddMultiColumnsIndexClusterIndex(t *testing.T) {
store := testkit.CreateMockStoreWithSchemaLease(t, indexModifyLease)
tk := testkit.NewTestKit(t, store)
tk.MustExec("drop database if exists test_add_multi_col_index_clustered;")
tk.MustExec("create database test_add_multi_col_index_clustered;")
tk.MustExec("use test_add_multi_col_index_clustered;")

tk.Session().GetSessionVars().EnableClusteredIndex = variable.ClusteredIndexDefModeOn
tk.MustExec("create table t (a int, b varchar(10), c int, primary key (a, b));")
tk.MustExec("insert into t values (1, '1', 1), (2, '2', NULL), (3, '3', 3);")
tk.MustExec("create index idx on t (a, c);")

tk.MustExec("admin check index t idx;")
tk.MustExec("admin check table t;")

tk.MustExec("insert into t values (5, '5', 5), (6, '6', NULL);")

tk.MustExec("admin check index t idx;")
tk.MustExec("admin check table t;")
}

func TestAddIndexWithDupCols(t *testing.T) {
store := testkit.CreateMockStoreWithSchemaLease(t, indexModifyLease)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")

err1 := infoschema.ErrColumnExists.GenWithStackByArgs("b")
err2 := infoschema.ErrColumnExists.GenWithStackByArgs("B")

tk.MustExec("create table test_add_index_with_dup (a int, b int)")
err := tk.ExecToErr("create index c on test_add_index_with_dup(b, a, b)")
require.ErrorIs(t, err, errors.Cause(err1))
err = tk.ExecToErr("create index c on test_add_index_with_dup(b, a, B)")
require.ErrorIs(t, err, errors.Cause(err2))
err = tk.ExecToErr("alter table test_add_index_with_dup add index c (b, a, b)")
require.ErrorIs(t, err, errors.Cause(err1))
err = tk.ExecToErr("alter table test_add_index_with_dup add index c (b, a, B)")
require.ErrorIs(t, err, errors.Cause(err2))

tk.MustExec("drop table test_add_index_with_dup")
}

func TestAnonymousIndex(t *testing.T) {
store := testkit.CreateMockStoreWithSchemaLease(t, indexModifyLease, mockstore.WithDDLChecker())

Expand Down
84 changes: 0 additions & 84 deletions ddl/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package ddl_test

import (
"fmt"
"testing"

"github.com/pingcap/tidb/ddl/util/callback"
Expand All @@ -24,63 +23,6 @@ import (
"github.com/stretchr/testify/require"
)

func TestDefaultValueIsBinaryString(t *testing.T) {
store := testkit.CreateMockStore(t)
tests := []struct {
colTp string
defVal string
result string
}{
{"char(10) charset gbk", "0xC4E3BAC3", "你好"},
{"char(10) charset gbk", "'好'", "好"},
{"varchar(10) charset gbk", "0xC4E3BAC3", "你好"},
{"char(10) charset utf8mb4", "0xE4BDA0E5A5BD", "你好"},
{"char(10) charset utf8mb4", "0b111001001011100010010110111001111001010110001100", "世界"},
{"bit(48)", "0xE4BDA0E5A5BD", "你好"},
{"enum('你好')", "0xE4BDA0E5A5BD", "你好"},
{"set('你好')", "0xE4BDA0E5A5BD", "你好"},
}
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test;")
for _, tt := range tests {
tk.MustExec("drop table if exists t;")
template := "create table t (a %s default %s);"
tk.MustExec(fmt.Sprintf(template, tt.colTp, tt.defVal))
tk.MustExec("insert into t values (default);")
tk.MustQuery("select a from t;").Check(testkit.Rows(tt.result))
}

// Test invalid default value.
tk.MustExec("drop table if exists t;")
// 0xE4BDA0E5A5BD81 is an invalid utf-8 string.
tk.MustGetErrMsg("create table t (a char(20) charset utf8mb4 default 0xE4BDA0E5A5BD81);",
"[ddl:1067]Invalid default value for 'a'")
tk.MustGetErrMsg("create table t (a blob default 0xE4BDA0E5A5BD81);",
"[ddl:1101]BLOB/TEXT/JSON column 'a' can't have a default value")
}

// https://github.com/pingcap/tidb/issues/30740.
func TestDefaultValueInEnum(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test;")
// The value 0x91 should not cause panic.
tk.MustExec("create table t(a enum('a', 0x91) charset gbk);")
tk.MustExec("insert into t values (1), (2);") // Use 1-base index to locate the value.
tk.MustQuery("select a from t;").Check(testkit.Rows("a", "?")) // 0x91 is replaced to '?'.
tk.MustExec("drop table t;")
tk.MustExec("create table t (a enum('a', 0x91)) charset gbk;") // Test for table charset.
tk.MustExec("insert into t values (1), (2);")
tk.MustQuery("select a from t;").Check(testkit.Rows("a", "?"))
tk.MustExec("drop table t;")
tk.MustGetErrMsg("create table t(a set('a', 0x91, '?') charset gbk);",
"[types:1291]Column 'a' has duplicated value '?' in SET")
// Test valid utf-8 string value in enum.
tk.MustExec("create table t (a enum('a', 0xE4BDA0E5A5BD) charset gbk);")
tk.MustExec("insert into t values (1), (2);")
tk.MustQuery("select a from t;").Check(testkit.Rows("a", "浣犲ソ"))
}

func TestDDLStatementsBackFill(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)
tk := testkit.NewTestKit(t, store)
Expand Down Expand Up @@ -116,29 +58,3 @@ func TestDDLStatementsBackFill(t *testing.T) {
require.Equal(t, tc.expectedNeedReorg, needReorg, tc)
}
}

func TestDDLOnCachedTable(t *testing.T) {
store := testkit.CreateMockStore(t)
tests := []struct {
sql string
result string
}{
{"drop table t", "[ddl:8242]'Drop Table' is unsupported on cache tables."},
{"create index t_id on t (id)", "[ddl:8242]'Create Index' is unsupported on cache tables."},
{"alter table t drop index c", "[ddl:8242]'Alter Table' is unsupported on cache tables."},
{"alter table t add column (d int)", "[ddl:8242]'Alter Table' is unsupported on cache tables."},
{"truncate table t", "[ddl:8242]'Truncate Table' is unsupported on cache tables."},
{"rename table t to t1", "[ddl:8242]'Rename Table' is unsupported on cache tables."},
}
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test;")
tk.MustExec("create table t (id int, c int, index(c));")
tk.MustExec("alter table t cache;")

for _, tt := range tests {
tk.MustGetErrMsg(tt.sql, tt.result)
}

tk.MustExec("alter table t nocache;")
tk.MustExec("drop table if exists t;")
}
Loading