-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
session_test: move tests #4699
Merged
Merged
session_test: move tests #4699
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -496,7 +496,7 @@ func (s *testSessionSuite) TestLastInsertID(c *C) { | |
tk.MustQuery("select last_insert_id()").Check(testkit.Rows("112")) | ||
} | ||
|
||
func (s *testSessionSuite) TestPrimaryKeyAutoincrement(c *C) { | ||
func (s *testSessionSuite) TestPrimaryKeyAutoIncrement(c *C) { | ||
tk := testkit.NewTestKitWithInit(c, s.store) | ||
tk.MustExec("drop table if exists t") | ||
tk.MustExec("create table t (id BIGINT PRIMARY KEY AUTO_INCREMENT NOT NULL, name varchar(255) UNIQUE NOT NULL, status int)") | ||
|
@@ -558,6 +558,99 @@ func (s *testSessionSuite) TestAutoIncrementID(c *C) { | |
tk.MustQuery("select last_insert_id()").Check(testkit.Rows(fmt.Sprint(20))) | ||
} | ||
|
||
func (s *testSessionSuite) TestAutoIncrementWithRetry(c *C) { | ||
// test for https://github.com/pingcap/tidb/issues/827 | ||
|
||
tk := testkit.NewTestKitWithInit(c, s.store) | ||
tk1 := testkit.NewTestKitWithInit(c, s.store) | ||
|
||
tk.MustExec("create table t (c2 int, c1 int not null auto_increment, PRIMARY KEY (c1))") | ||
tk.MustExec("insert into t (c2) values (1), (2), (3), (4), (5)") | ||
|
||
// insert values | ||
lastInsertID := tk.Se.LastInsertID() | ||
tk.MustExec("begin") | ||
tk.MustExec("insert into t (c2) values (11), (12), (13)") | ||
tk.MustQuery("select c1 from t where c2 = 11").Check(testkit.Rows("6")) | ||
tk.MustExec("update t set c2 = 33 where c2 = 1") | ||
|
||
tk1.MustExec("update t set c2 = 22 where c2 = 1") | ||
|
||
tk.MustExec("commit") | ||
|
||
tk.MustQuery("select c1 from t where c2 = 11").Check(testkit.Rows("6")) | ||
currLastInsertID := tk.Se.GetSessionVars().PrevLastInsertID | ||
c.Assert(lastInsertID+5, Equals, currLastInsertID) | ||
|
||
// insert set | ||
lastInsertID = currLastInsertID | ||
tk.MustExec("begin") | ||
tk.MustExec("insert into t set c2 = 31") | ||
tk.MustQuery("select c1 from t where c2 = 31").Check(testkit.Rows("9")) | ||
tk.MustQuery("update t set c2 = 44 where c2 = 2") | ||
|
||
tk1.MustExec("update t set c2 = 55 where c2 = 2") | ||
|
||
tk.MustExec("commit") | ||
|
||
tk.MustQuery("select c1 from t where c2 = 31").Check(testkit.Rows("9")) | ||
currLastInsertID = tk.Se.GetSessionVars().PrevLastInsertID | ||
c.Assert(lastInsertID+3, Equals, currLastInsertID) | ||
|
||
// replace | ||
lastInsertID = currLastInsertID | ||
tk.MustExec("begin") | ||
tk.MustExec("insert into t (c2) values (21), (22), (23)") | ||
tk.MustQuery("select c1 from t where c2 = 21").Check(testkit.Rows("10")) | ||
tk.MustExec("update t set c2 = 66 where c2 = 3") | ||
|
||
tk1.MustExec("update t set c2 = 77 where c2 = 3") | ||
|
||
tk.MustExec("commit") | ||
|
||
tk.MustQuery("select c1 from t where c2 = 21").Check(testkit.Rows("10")) | ||
currLastInsertID = tk.Se.GetSessionVars().PrevLastInsertID | ||
c.Assert(lastInsertID+1, Equals, currLastInsertID) | ||
|
||
// update | ||
lastInsertID = currLastInsertID | ||
tk.MustExec("begin") | ||
tk.MustExec("insert into t set c2 = 41") | ||
tk.MustExec("update t set c1 = 0 where c2 = 41") | ||
tk.MustQuery("select c1 from t where c2 = 41").Check(testkit.Rows("0")) | ||
tk.MustExec("update t set c2 = 88 where c2 = 4") | ||
|
||
tk1.MustExec("update t set c2 = 99 where c2 = 4") | ||
|
||
tk.MustExec("commit") | ||
|
||
tk.MustQuery("select c1 from t where c2 = 41").Check(testkit.Rows("0")) | ||
currLastInsertID = tk.Se.GetSessionVars().PrevLastInsertID | ||
c.Assert(lastInsertID+3, Equals, currLastInsertID) | ||
|
||
// prepare | ||
lastInsertID = currLastInsertID | ||
tk.MustExec("begin") | ||
tk.MustExec("prepare stmt from 'insert into t (c2) values (?)'") | ||
tk.MustExec("set @v1=100") | ||
tk.MustExec("set @v2=200") | ||
tk.MustExec("set @v3=300") | ||
tk.MustExec("execute stmt using @v1") | ||
tk.MustExec("execute stmt using @v2") | ||
tk.MustExec("execute stmt using @v3") | ||
tk.MustExec("deallocate prepare stmt") | ||
tk.MustQuery("select c1 from t where c2 = 12").Check(testkit.Rows()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
tk.MustExec("update t set c2 = 111 where c2 = 5") | ||
|
||
tk1.MustExec("update t set c2 = 222 where c2 = 5") | ||
|
||
tk.MustExec("commit") | ||
|
||
tk.MustQuery("select c1 from t where c2 = 12").Check(testkit.Rows()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
currLastInsertID = tk.Se.GetSessionVars().PrevLastInsertID | ||
c.Assert(lastInsertID+3, Equals, currLastInsertID) | ||
} | ||
|
||
func (s *testSessionSuite) TestPrepare(c *C) { | ||
tk := testkit.NewTestKitWithInit(c, s.store) | ||
tk.MustExec("create table t(id TEXT)") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MustExec