Skip to content

Commit

Permalink
test: merge serial tests in ddl, infoschema, session, store, table, t…
Browse files Browse the repository at this point in the history
…elemetry and types (#30874)
  • Loading branch information
tangenta authored Dec 23, 2021
1 parent e24493f commit 4dc385c
Show file tree
Hide file tree
Showing 29 changed files with 1,022 additions and 1,175 deletions.
97 changes: 0 additions & 97 deletions ddl/db_cache_serial_test.go

This file was deleted.

70 changes: 70 additions & 0 deletions ddl/db_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ package ddl_test

import (
"testing"
"time"

"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/errno"
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/parser/terror"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/testkit"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -133,3 +137,69 @@ func TestIndexOnCacheTable(t *testing.T) {
tk.MustExec("alter table cache_index_1 cache")
tk.MustGetErrCode("alter table cache_index_1 drop index i1, drop index i2;", errno.ErrOptOnCacheTable)
}

func TestAlterTableCache(t *testing.T) {
store, err := mockstore.NewMockStore()
require.NoError(t, err)
session.SetSchemaLease(600 * time.Millisecond)
session.DisableStats4Test()
dom, err := session.BootstrapSession(store)
require.NoError(t, err)

dom.SetStatsUpdating(true)

clean := func() {
dom.Close()
err := store.Close()
require.NoError(t, err)
}
defer clean()
tk := testkit.NewTestKit(t, store)
tk2 := testkit.NewTestKit(t, store)

tk.MustExec("use test")
tk.MustExec("drop table if exists t1")
tk2.MustExec("use test")
/* Test of cache table */
tk.MustExec("create table t1 ( n int auto_increment primary key)")
tk.MustGetErrCode("alter table t1 ca", errno.ErrParse)
tk.MustGetErrCode("alter table t2 cache", errno.ErrNoSuchTable)
tk.MustExec("alter table t1 cache")
checkTableCacheStatus(t, tk.Session(), "test", "t1", model.TableCacheStatusEnable)
tk.MustExec("drop table if exists t1")
/*Test can't skip schema checker*/
tk.MustExec("drop table if exists t1,t2")
tk.MustExec("CREATE TABLE t1 (a int)")
tk.MustExec("CREATE TABLE t2 (a int)")
tk.MustExec("begin")
tk.MustExec("insert into t1 set a=1;")
tk2.MustExec("alter table t1 cache;")
_, err = tk.Exec("commit")
require.True(t, terror.ErrorEqual(domain.ErrInfoSchemaChanged, err))
/* Test can skip schema checker */
tk.MustExec("begin")
tk.MustExec("drop table if exists t1")
tk.MustExec("CREATE TABLE t1 (a int)")
tk.MustExec("insert into t1 set a=2;")
tk2.MustExec("alter table t2 cache")
tk.MustExec("commit")
// Test if a table is not exists
tk.MustExec("drop table if exists t")
tk.MustGetErrCode("alter table t cache", errno.ErrNoSuchTable)
tk.MustExec("create table t (a int)")
tk.MustExec("alter table t cache")
// Multiple alter cache is okay
tk.MustExec("alter table t cache")
tk.MustExec("alter table t cache")
// Test a temporary table
tk.MustExec("drop table if exists t")
tk.MustExec("create temporary table t (id int primary key auto_increment, u int unique, v int)")
tk.MustExec("drop table if exists tmp1")
// local temporary table alter is not supported
tk.MustGetErrCode("alter table t cache", errno.ErrUnsupportedDDLOperation)
// test global temporary table
tk.MustExec("create global temporary table tmp1 " +
"(id int not null primary key, code int not null, value int default null, unique key code(code))" +
"on commit delete rows")
tk.MustGetErrMsg("alter table tmp1 cache", ddl.ErrOptOnTemporaryTable.GenWithStackByArgs("alter temporary table cache").Error())
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
159 changes: 0 additions & 159 deletions infoschema/perfschema/tables_serial_test.go

This file was deleted.

Loading

0 comments on commit 4dc385c

Please sign in to comment.