From d3833c2ab2b65ccd80731b9f982c8565df8b6407 Mon Sep 17 00:00:00 2001 From: lvtu <37565148+tongtongyin@users.noreply.github.com> Date: Mon, 13 Dec 2021 18:14:35 +0800 Subject: [PATCH] executor: migrate test-infra to testify for executor/union_scan_test.go (#30525) --- 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..1fe3f4dbbacbc 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) { + 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;") @@ -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')") @@ -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))") @@ -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")) @@ -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") @@ -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);") @@ -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")