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

Support "pause" a session in unit test #35526

Closed
lcwangchao opened this issue Jun 20, 2022 · 1 comment · Fixed by #35529
Closed

Support "pause" a session in unit test #35526

lcwangchao opened this issue Jun 20, 2022 · 1 comment · Fixed by #35529
Labels
type/enhancement The issue or PR belongs to an enhancement.

Comments

@lcwangchao
Copy link
Collaborator

Enhancement

Some times in a uint test, we want to "pause" a session manually and then "resume" it to run some other codes between them. For example, if we want to test the retry operation when it has a key conflict , we need to:

  1. Execute "update t set v=v+1 where id=1" in session1, PAUSE this session after it updated the record in memory before committed to TiKV.
  2. Create a new session2, and update the same record.
  3. RESUME the session1 to continue the commit works. At this time, we expect a conflict error from TiKV. The session1 retries then, and finally write the right value.

However, the current MustExec or MustQuery will block the execute goroutine and will not return util the whole statement is finished, so we need other utils to make the pause and resume semantics. It looks like the below codes:

// initial value for table t is (1, 10)
tk1 := testkit.NewTestKit(t, store)
task := CreateExecTask("update t set v=v+1 where id=1")

// Create a sql task and start it and pause it before commit
task.Start().CheckStopAt("before commit")
// Then tk1 update the record to construct the conflict
tk1.MustExec("update t set v=v+1 where id=1")
// Continue the task and check it stop at commit retry because of error
task.Continue().CheckStopAt("commit retry")
// Then continue again the task to done
task.Continue().CheckDone()
// Check the final value is 12 not 11
tk1.MustQuery("select v from t where id=1").Check(testkit.Rows("1 12"))
@lcwangchao lcwangchao added the type/enhancement The issue or PR belongs to an enhancement. label Jun 20, 2022
@morgo
Copy link
Contributor

morgo commented Jun 20, 2022

I think there are some tests that use the sql SLEEP() function which could be fixed to use this instead :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants