Skip to content

Commit

Permalink
*: add some tests for writing-data corner cases (pingcap#9199)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackysp authored and lysu committed Feb 11, 2019
1 parent 2ea6e1b commit 640aa65
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
20 changes: 20 additions & 0 deletions executor/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"sync/atomic"

. "github.com/pingcap/check"
gofail "github.com/pingcap/gofail/runtime"
"github.com/pingcap/parser/model"
"github.com/pingcap/tidb/executor"
"github.com/pingcap/tidb/kv"
Expand Down Expand Up @@ -1270,6 +1271,8 @@ func (s *testSuite) TestUpdate(c *C) {
r1 := tk.MustQuery("select ts from tsup use index (idx);")
r2 := tk.MustQuery("select ts from tsup;")
r1.Check(r2.Rows())
tk.MustExec("update tsup set ts='2019-01-01';")
tk.MustQuery("select ts from tsup;").Check(testkit.Rows("2019-01-01 00:00:00"))

// issue 5532
tk.MustExec("create table decimals (a decimal(20, 0) not null)")
Expand Down Expand Up @@ -2433,3 +2436,20 @@ func (s *testSuite2) TestDefEnumInsert(c *C) {
tk.MustExec("insert into test (id) values (1)")
tk.MustQuery("select prescription_type from test").Check(testkit.Rows("a"))
}

func (s *testSuite2) TestAutoIDInRetry(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("create table t (id int not null auto_increment primary key)")

tk.MustExec("begin")
tk.MustExec("insert into t values ()")
tk.MustExec("insert into t values (),()")
tk.MustExec("insert into t values ()")

gofail.Enable("github.com/pingcap/tidb/session/mockCommitRetryForAutoID", `return(true)`)
tk.MustExec("commit")
gofail.Disable("github.com/pingcap/tidb/session/mockCommitRetryForAutoID")

tk.MustExec("insert into t values ()")
tk.MustQuery(`select * from t`).Check(testkit.Rows("1", "2", "3", "4", "5"))
}
9 changes: 9 additions & 0 deletions session/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ type dirtyTableOperation struct {
row []types.Datum
}

var hasMockAutoIDRetry = false

// Commit overrides the Transaction interface.
func (st *TxnState) Commit(ctx context.Context) error {
defer st.reset()
Expand All @@ -171,6 +173,13 @@ func (st *TxnState) Commit(ctx context.Context) error {
// return kv.ErrRetryable
// }

// mockCommitRetryForAutoID is used to mock an commit retry for adjustAutoIncrementDatum.
// gofail: var mockCommitRetryForAutoID bool
// if mockCommitRetryForAutoID && !hasMockAutoIDRetry {
// hasMockAutoIDRetry = true
// return kv.ErrRetryable
// }

return errors.Trace(st.Transaction.Commit(ctx))
}

Expand Down

0 comments on commit 640aa65

Please sign in to comment.