Skip to content

Commit

Permalink
executor: migrate test-infra to testify for executor/union_scan_test.…
Browse files Browse the repository at this point in the history
…go (#30525)
  • Loading branch information
tongtongyin authored Dec 13, 2021
1 parent a532973 commit d3833c2
Showing 1 changed file with 38 additions and 19 deletions.
57 changes: 38 additions & 19 deletions executor/union_scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ package executor_test

import (
"fmt"
"testing"

. "github.com/pingcap/check"
"github.com/pingcap/tidb/util/testkit"
"github.com/pingcap/tidb/testkit"
"github.com/stretchr/testify/require"
)

func (s *testSuite7) TestDirtyTransaction(c *C) {
tk := testkit.NewTestKit(c, s.store)
func TestDirtyTransaction(t *testing.T) {
t.Parallel()
store, clean := testkit.CreateMockStore(t)
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustExec("set @@session.tidb_executor_concurrency = 4;")
tk.MustExec("set @@session.tidb_hash_join_concurrency = 5;")
tk.MustExec("set @@session.tidb_distsql_scan_concurrency = 15;")
Expand Down Expand Up @@ -149,8 +153,11 @@ func (s *testSuite7) TestDirtyTransaction(c *C) {
tk.MustExec("commit;")
}

func (s *testSuite7) TestUnionScanWithCastCondition(c *C) {
tk := testkit.NewTestKit(c, s.store)
func TestUnionScanWithCastCondition(t *testing.T) {
t.Parallel()
store, clean := testkit.CreateMockStore(t)
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table ta (a varchar(20))")
tk.MustExec("insert ta values ('1'), ('2')")
Expand All @@ -162,8 +169,11 @@ func (s *testSuite7) TestUnionScanWithCastCondition(c *C) {
tk.MustExec("rollback")
}

func (s *testSuite7) TestUnionScanForMemBufferReader(c *C) {
tk := testkit.NewTestKit(c, s.store)
func TestUnionScanForMemBufferReader(t *testing.T) {
t.Parallel()
store, clean := testkit.CreateMockStore(t)
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t (a int,b int, index idx(b))")
Expand Down Expand Up @@ -214,8 +224,8 @@ func (s *testSuite7) TestUnionScanForMemBufferReader(c *C) {
tk.MustExec("insert t values (1,1),(2,2)")
tk.MustExec("begin")
_, err := tk.Exec("update t set b=b+1")
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[kv:1062]Duplicate entry '2' for key 'idx'")
require.NotNil(t, err)
require.EqualError(t, err, "[kv:1062]Duplicate entry '2' for key 'idx'")
// update with unchange index column.
tk.MustExec("update t set a=a+1")
tk.MustQuery("select * from t use index (idx)").Check(testkit.Rows("2 1", "3 2"))
Expand Down Expand Up @@ -298,8 +308,11 @@ func (s *testSuite7) TestUnionScanForMemBufferReader(c *C) {
tk.MustExec("admin check table t1;")
}

func (s *testSuite7) TestForUpdateUntouchedIndex(c *C) {
tk := testkit.NewTestKit(c, s.store)
func TestForUpdateUntouchedIndex(t *testing.T) {
t.Parallel()
store, clean := testkit.CreateMockStore(t)
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")

Expand Down Expand Up @@ -330,14 +343,17 @@ func (s *testSuite7) TestForUpdateUntouchedIndex(c *C) {
tk.MustExec("create table t (a int,b int, unique index(a))")
tk.MustExec("begin")
_, err := tk.Exec("insert into t values (1, 1), (2, 2), (1, 3) on duplicate key update a = a + 1;")
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[kv:1062]Duplicate entry '2' for key 'a'")
require.NotNil(t, err)
require.EqualError(t, err, "[kv:1062]Duplicate entry '2' for key 'a'")
tk.MustExec("commit")
tk.MustExec("admin check table t")
}

func (s *testSuite7) TestUpdateScanningHandles(c *C) {
tk := testkit.NewTestKit(c, s.store)
func TestUpdateScanningHandles(t *testing.T) {
t.Parallel()
store, clean := testkit.CreateMockStore(t)
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t;")
tk.MustExec("create table t(a int primary key, b int);")
Expand All @@ -363,13 +379,16 @@ func (s *testSuite7) TestUpdateScanningHandles(c *C) {
tk.MustExec("insert into t values (1, 1);")
tk.MustExec("update /*+ INL_JOIN(t1) */ t t1, (select a, b from t) t2 set t1.b = t2.b where t1.a = t2.a + 1000;")
result := tk.MustQuery("select a, a-b from t where a > 1000 and a - b != 1000;")
c.Assert(result.Rows(), HasLen, 0)
require.Len(t, result.Rows(), 0)
tk.MustExec("rollback;")
}

// See https://github.com/pingcap/tidb/issues/19136
func (s *testSuite7) TestForApplyAndUnionScan(c *C) {
tk := testkit.NewTestKit(c, s.store)
func TestForApplyAndUnionScan(t *testing.T) {
t.Parallel()
store, clean := testkit.CreateMockStore(t)
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")

Expand Down

0 comments on commit d3833c2

Please sign in to comment.