Skip to content

Support "pause" a session in unit test #35526

@lcwangchao

Description

@lcwangchao

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"))

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/enhancementThe issue or PR belongs to an enhancement.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions