From 0691ecc9a5d3835ef78185b0a713c5f491393802 Mon Sep 17 00:00:00 2001 From: djshow832 <873581766@qq.com> Date: Mon, 2 Mar 2020 23:14:27 +0800 Subject: [PATCH] add test cases --- go.mod | 2 +- go.sum | 4 ++-- session/session_test.go | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index b3aa403806dac..84b36787ea014 100644 --- a/go.mod +++ b/go.mod @@ -38,7 +38,7 @@ require ( github.com/pingcap/goleveldb v0.0.0-20171020122428-b9ff6c35079e github.com/pingcap/kvproto v0.0.0-20191106014506-c5d88d699a8d github.com/pingcap/log v0.0.0-20190715063458-479153f07ebd - github.com/pingcap/parser v0.0.0-20200108075733-73763c7a9133 + github.com/pingcap/parser v0.0.0-20200301155133-79ec3dee69a5 github.com/pingcap/pd v1.1.0-beta.0.20191223090411-ea2b748f6ee2 github.com/pingcap/tidb-tools v3.0.6-0.20191119150227-ff0a3c6e5763+incompatible github.com/pingcap/tipb v0.0.0-20191120045257-1b9900292ab6 diff --git a/go.sum b/go.sum index 183a22d8dd892..62dd659803480 100644 --- a/go.sum +++ b/go.sum @@ -155,8 +155,8 @@ github.com/pingcap/kvproto v0.0.0-20191106014506-c5d88d699a8d h1:zTHgLr8+0LTEJmj github.com/pingcap/kvproto v0.0.0-20191106014506-c5d88d699a8d/go.mod h1:QMdbTAXCHzzygQzqcG9uVUgU2fKeSN1GmfMiykdSzzY= github.com/pingcap/log v0.0.0-20190715063458-479153f07ebd h1:hWDol43WY5PGhsh3+8794bFHY1bPrmu6bTalpssCrGg= github.com/pingcap/log v0.0.0-20190715063458-479153f07ebd/go.mod h1:WpHUKhNZ18v116SvGrmjkA9CBhYmuUTKL+p8JC9ANEw= -github.com/pingcap/parser v0.0.0-20200108075733-73763c7a9133 h1:/8H/v/T1nwDGSuiI/DLwWEvGbamR6LZxwyYPD4DGPDk= -github.com/pingcap/parser v0.0.0-20200108075733-73763c7a9133/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA= +github.com/pingcap/parser v0.0.0-20200301155133-79ec3dee69a5 h1:r2c8RQynYNGCFDWFPgo3TNx7Roq94STRcYTrtTg3JQ4= +github.com/pingcap/parser v0.0.0-20200301155133-79ec3dee69a5/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA= github.com/pingcap/pd v1.1.0-beta.0.20191223090411-ea2b748f6ee2 h1:NL23b8tsg6M1QpSQedK14/Jx++QeyKL2rGiBvXAQVfA= github.com/pingcap/pd v1.1.0-beta.0.20191223090411-ea2b748f6ee2/go.mod h1:b4gaAPSxaVVtaB+EHamV4Nsv8JmTdjlw0cTKmp4+dRQ= github.com/pingcap/tidb-tools v3.0.6-0.20191119150227-ff0a3c6e5763+incompatible h1:I8HirWsu1MZp6t9G/g8yKCEjJJxtHooKakEgccvdJ4M= diff --git a/session/session_test.go b/session/session_test.go index 49f55783889c5..ec9c1b2f838bd 100644 --- a/session/session_test.go +++ b/session/session_test.go @@ -589,6 +589,40 @@ func (s *testSessionSuite) TestReadOnlyNotInHistory(c *C) { c.Assert(history.Count(), Equals, 0) } +func (s *testSessionSuite) TestRetryUnion(c *C) { + tk := testkit.NewTestKitWithInit(c, s.store) + tk.MustExec("create table history (a int)") + tk.MustExec("insert history values (1), (2), (3)") + tk.MustExec("set @@autocommit = 0") + tk.MustExec("set tidb_disable_txn_auto_retry = 0") + // UNION should't be in retry history. + tk.MustQuery("(select * from history) union (select * from history)") + history := session.GetHistory(tk.Se) + c.Assert(history.Count(), Equals, 0) + tk.MustQuery("(select * from history for update) union (select * from history)") + tk.MustExec("update history set a = a + 1") + history = session.GetHistory(tk.Se) + c.Assert(history.Count(), Equals, 2) + + // Make retryable error. + tk1 := testkit.NewTestKitWithInit(c, s.store) + tk1.MustExec("update history set a = a + 1") + + _, err := tk.Exec("commit") + c.Assert(err, ErrorMatches, ".*can not retry select for update statement") +} + +func (s *testSessionSuite) TestRetryShow(c *C) { + tk := testkit.NewTestKitWithInit(c, s.store) + tk.MustExec("set @@autocommit = 0") + tk.MustExec("set tidb_disable_txn_auto_retry = 0") + // UNION should't be in retry history. + tk.MustQuery("show variables") + tk.MustQuery("show databases") + history := session.GetHistory(tk.Se) + c.Assert(history.Count(), Equals, 0) +} + // TestTruncateAlloc tests that the auto_increment ID does not reuse the old table's allocator. func (s *testSessionSuite) TestTruncateAlloc(c *C) { tk := testkit.NewTestKitWithInit(c, s.store)