Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

txn, session, test: Try to stabilize testTxnStateSerialSuite.TestRunning and TestBlocked #27235

Merged
merged 17 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,11 @@ func (s *session) ExecuteStmt(ctx context.Context, stmtNode ast.StmtNode) (sqlex
s.txn.onStmtStart(digest.String())
defer s.txn.onStmtEnd()

failpoint.Inject("mockStmtSlow", nil)
failpoint.Inject("mockStmtSlow", func(val failpoint.Value) {
if strings.Contains(stmtNode.Text(), "/* sleep */") {
time.Sleep(time.Duration(val.(int)) * time.Millisecond)
}
})

// Transform abstract syntax tree to a physical plan(stored in executor.ExecStmt).
compiler := executor.Compiler{Ctx: s}
Expand Down
14 changes: 10 additions & 4 deletions session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4486,15 +4486,18 @@ func (s *testTxnStateSerialSuite) TestRunning(c *C) {
tk.MustExec("create table t(a int);")
tk.MustExec("insert into t(a) values (1);")
tk.MustExec("begin pessimistic;")
failpoint.Enable("github.com/pingcap/tidb/session/mockStmtSlow", "sleep(100)")
c.Assert(failpoint.Enable("github.com/pingcap/tidb/session/mockStmtSlow", "return(200)"), IsNil)
ch := make(chan struct{})
go func() {
tk.MustExec("select * from t for update;")
tk.MustExec("select * from t for update /* sleep */;")
tk.MustExec("commit;")
ch <- struct{}{}
}()
time.Sleep(20 * time.Millisecond)
time.Sleep(100 * time.Millisecond)
info := tk.Se.TxnInfo()
c.Assert(info.State, Equals, txninfo.TxnRunning)
failpoint.Disable("github.com/pingcap/tidb/session/mockStmtSlow")
c.Assert(failpoint.Disable("github.com/pingcap/tidb/session/mockStmtSlow"), IsNil)
<-ch
}

func (s *testTxnStateSerialSuite) TestBlocked(c *C) {
Expand All @@ -4504,15 +4507,18 @@ func (s *testTxnStateSerialSuite) TestBlocked(c *C) {
tk.MustExec("insert into t(a) values (1);")
tk.MustExec("begin pessimistic;")
tk.MustExec("select * from t where a = 1 for update;")
ch := make(chan struct{})
go func() {
tk2.MustExec("begin pessimistic")
tk2.MustExec("select * from t where a = 1 for update;")
tk2.MustExec("commit;")
ch <- struct{}{}
}()
time.Sleep(100 * time.Millisecond)
c.Assert(tk2.Se.TxnInfo().State, Equals, txninfo.TxnLockWaiting)
c.Assert(tk2.Se.TxnInfo().BlockStartTime, NotNil)
tk.MustExec("commit;")
<-ch
}

func (s *testTxnStateSerialSuite) TestCommitting(c *C) {
Expand Down