From f8c1aa110869b67e9e51cfd99956e5f22703a455 Mon Sep 17 00:00:00 2001 From: lvtu Date: Wed, 8 Dec 2021 12:50:47 +0800 Subject: [PATCH 1/5] executor: migrate test-infra to testify for executor/union_scan_test.go --- executor/union_scan_test.go | 57 ++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/executor/union_scan_test.go b/executor/union_scan_test.go index 5e0727458230e..b7e418738a4c5 100644 --- a/executor/union_scan_test.go +++ b/executor/union_scan_test.go @@ -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) { + 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;") @@ -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) { + 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')") @@ -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) { + 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))") @@ -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.Equal(t, "[kv:1062]Duplicate entry '2' for key 'idx'", err.Error()) // 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")) @@ -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) { + store, clean := testkit.CreateMockStore(t) + defer clean() + + tk := testkit.NewTestKit(t, store) tk.MustExec("use test") tk.MustExec("drop table if exists t") @@ -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.Equal(t, "[kv:1062]Duplicate entry '2' for key 'a'", err.Error()) 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) { + 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);") @@ -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) { + store, clean := testkit.CreateMockStore(t) + defer clean() + + tk := testkit.NewTestKit(t, store) tk.MustExec("use test") tk.MustExec("drop table if exists t") From 3dce90a95b697bb826159ed7ac30b69263e42653 Mon Sep 17 00:00:00 2001 From: lvtu Date: Wed, 8 Dec 2021 14:07:08 +0800 Subject: [PATCH 2/5] executor: migrate test-infra to testify for executor/union_scan_test.go --- executor/union_scan_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/executor/union_scan_test.go b/executor/union_scan_test.go index b7e418738a4c5..57ceac1ac8db2 100644 --- a/executor/union_scan_test.go +++ b/executor/union_scan_test.go @@ -23,6 +23,8 @@ import ( ) func TestDirtyTransaction(t *testing.T) { + t.Parallel() + store, clean := testkit.CreateMockStore(t) defer clean() @@ -154,6 +156,8 @@ func TestDirtyTransaction(t *testing.T) { } func TestUnionScanWithCastCondition(t *testing.T) { + t.Parallel() + store, clean := testkit.CreateMockStore(t) defer clean() @@ -170,6 +174,8 @@ func TestUnionScanWithCastCondition(t *testing.T) { } func TestUnionScanForMemBufferReader(t *testing.T) { + t.Parallel() + store, clean := testkit.CreateMockStore(t) defer clean() @@ -309,6 +315,8 @@ func TestUnionScanForMemBufferReader(t *testing.T) { } func TestForUpdateUntouchedIndex(t *testing.T) { + t.Parallel() + store, clean := testkit.CreateMockStore(t) defer clean() @@ -350,6 +358,8 @@ func TestForUpdateUntouchedIndex(t *testing.T) { } func TestUpdateScanningHandles(t *testing.T) { + t.Parallel() + store, clean := testkit.CreateMockStore(t) defer clean() @@ -385,6 +395,8 @@ func TestUpdateScanningHandles(t *testing.T) { // See https://github.com/pingcap/tidb/issues/19136 func TestForApplyAndUnionScan(t *testing.T) { + t.Parallel() + store, clean := testkit.CreateMockStore(t) defer clean() From becc6cfa64859970a28f4f16d27b448d11b433b4 Mon Sep 17 00:00:00 2001 From: lvtu Date: Wed, 8 Dec 2021 14:22:11 +0800 Subject: [PATCH 3/5] executor: migrate test-infra to testify for executor/union_scan_test.go --- executor/union_scan_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor/union_scan_test.go b/executor/union_scan_test.go index 57ceac1ac8db2..8e9f8fda88471 100644 --- a/executor/union_scan_test.go +++ b/executor/union_scan_test.go @@ -396,7 +396,7 @@ func TestUpdateScanningHandles(t *testing.T) { // See https://github.com/pingcap/tidb/issues/19136 func TestForApplyAndUnionScan(t *testing.T) { t.Parallel() - + store, clean := testkit.CreateMockStore(t) defer clean() From 590b996530060232958c2e30aabef377de3b470a Mon Sep 17 00:00:00 2001 From: lvtu Date: Wed, 8 Dec 2021 14:37:07 +0800 Subject: [PATCH 4/5] executor: migrate test-infra to testify for executor/union_scan_test.go --- executor/union_scan_test.go | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/executor/union_scan_test.go b/executor/union_scan_test.go index 8e9f8fda88471..6bb37a4139b24 100644 --- a/executor/union_scan_test.go +++ b/executor/union_scan_test.go @@ -24,10 +24,8 @@ import ( 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;") @@ -157,10 +155,8 @@ func TestDirtyTransaction(t *testing.T) { 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))") @@ -175,10 +171,8 @@ func TestUnionScanWithCastCondition(t *testing.T) { 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") @@ -316,10 +310,8 @@ func TestUnionScanForMemBufferReader(t *testing.T) { 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") @@ -359,10 +351,8 @@ func TestForUpdateUntouchedIndex(t *testing.T) { 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;") @@ -396,10 +386,8 @@ func TestUpdateScanningHandles(t *testing.T) { // See https://github.com/pingcap/tidb/issues/19136 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") From f6989df422148d6ca313547450fc92f7f4d58068 Mon Sep 17 00:00:00 2001 From: lvtu Date: Wed, 8 Dec 2021 16:11:58 +0800 Subject: [PATCH 5/5] executor: migrate test-infra to testify for executor/union_scan_test.go --- executor/union_scan_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/executor/union_scan_test.go b/executor/union_scan_test.go index 6bb37a4139b24..1fe3f4dbbacbc 100644 --- a/executor/union_scan_test.go +++ b/executor/union_scan_test.go @@ -225,7 +225,7 @@ func TestUnionScanForMemBufferReader(t *testing.T) { tk.MustExec("begin") _, err := tk.Exec("update t set b=b+1") require.NotNil(t, err) - require.Equal(t, "[kv:1062]Duplicate entry '2' for key 'idx'", err.Error()) + 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")) @@ -344,7 +344,7 @@ func TestForUpdateUntouchedIndex(t *testing.T) { tk.MustExec("begin") _, err := tk.Exec("insert into t values (1, 1), (2, 2), (1, 3) on duplicate key update a = a + 1;") require.NotNil(t, err) - require.Equal(t, "[kv:1062]Duplicate entry '2' for key 'a'", err.Error()) + require.EqualError(t, err, "[kv:1062]Duplicate entry '2' for key 'a'") tk.MustExec("commit") tk.MustExec("admin check table t") }