Skip to content

Commit

Permalink
*: Always rollback after tests in isolation to make tests stable (#36219
Browse files Browse the repository at this point in the history
)

close #36212
  • Loading branch information
lcwangchao authored Jul 14, 2022
1 parent 6da1cbe commit 987bdd3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sessiontxn/isolation/optimistic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func TestOptimisticTxnContextProviderTS(t *testing.T) {
defer clean()

tk := testkit.NewTestKit(t, store)
defer tk.MustExec("rollback")

tk.MustExec("use test")
tk.MustExec("create table t(id int primary key, v int)")

Expand Down Expand Up @@ -132,6 +134,8 @@ func TestOptimisticHandleError(t *testing.T) {
defer clean()

tk := testkit.NewTestKit(t, store)
defer tk.MustExec("rollback")

provider := initializeOptimisticProvider(t, tk, true)
startTS := tk.Session().GetSessionVars().TxnCtx.StartTS
checkTS := func() {
Expand Down Expand Up @@ -214,6 +218,8 @@ func TestOptimisticProviderInitialize(t *testing.T) {
defer clearScopeSettings()

tk := testkit.NewTestKit(t, store)
defer tk.MustExec("rollback")

se := tk.Session()

// begin outside a txn
Expand Down Expand Up @@ -286,6 +292,8 @@ func TestTidbSnapshotVarInOptimisticTxn(t *testing.T) {
defer clean()

tk := testkit.NewTestKit(t, store)
defer tk.MustExec("rollback")

se := tk.Session()
tk.MustExec("set @@tx_isolation = 'READ-COMMITTED'")
safePoint := "20160102-15:04:05 -0700"
Expand Down
18 changes: 18 additions & 0 deletions sessiontxn/isolation/readcommitted_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func TestPessimisticRCTxnContextProviderRCCheck(t *testing.T) {
defer clean()

tk := testkit.NewTestKit(t, store)
defer tk.MustExec("rollback")

tk.MustExec("set @@tidb_rc_read_check_ts=1")
se := tk.Session()
provider := initializePessimisticRCProvider(t, tk)
Expand Down Expand Up @@ -145,7 +147,11 @@ func TestPessimisticRCTxnContextProviderRCCheckForPrepareExecute(t *testing.T) {
defer clean()

tk := testkit.NewTestKit(t, store)
defer tk.MustExec("rollback")

tk2 := testkit.NewTestKit(t, store)
defer tk2.MustExec("rollback")

tk.MustExec("use test")
tk2.MustExec("use test")
tk.MustExec("create table t (id int primary key, v int)")
Expand Down Expand Up @@ -199,6 +205,8 @@ func TestPessimisticRCTxnContextProviderLockError(t *testing.T) {
defer clean()

tk := testkit.NewTestKit(t, store)
defer tk.MustExec("rollback")

se := tk.Session()
provider := initializePessimisticRCProvider(t, tk)

Expand Down Expand Up @@ -236,6 +244,8 @@ func TestPessimisticRCTxnContextProviderTS(t *testing.T) {
defer clean()

tk := testkit.NewTestKit(t, store)
defer tk.MustExec("rollback")

se := tk.Session()
provider := initializePessimisticRCProvider(t, tk)
compareTS := getOracleTS(t, se)
Expand Down Expand Up @@ -293,6 +303,8 @@ func TestRCProviderInitialize(t *testing.T) {
defer clearScopeSettings()

tk := testkit.NewTestKit(t, store)
defer tk.MustExec("rollback")

se := tk.Session()
tk.MustExec("set @@tx_isolation = 'READ-COMMITTED'")
tk.MustExec("set @@tidb_txn_mode='pessimistic'")
Expand Down Expand Up @@ -355,6 +367,8 @@ func TestTidbSnapshotVarInRC(t *testing.T) {
defer clean()

tk := testkit.NewTestKit(t, store)
defer tk.MustExec("rollback")

se := tk.Session()
tk.MustExec("set @@tx_isolation = 'READ-COMMITTED'")
safePoint := "20160102-15:04:05 -0700"
Expand Down Expand Up @@ -447,8 +461,12 @@ func TestConflictErrorsInRC(t *testing.T) {
defer clean()

tk := testkit.NewTestKit(t, store)
defer tk.MustExec("rollback")

se := tk.Session()

tk2 := testkit.NewTestKit(t, store)
defer tk2.MustExec("rollback")

tk.MustExec("use test")
tk2.MustExec("use test")
Expand Down
13 changes: 13 additions & 0 deletions sessiontxn/isolation/repeatable_read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func TestPessimisticRRErrorHandle(t *testing.T) {
store, _, clean := testkit.CreateMockStoreAndDomain(t)
defer clean()
tk := testkit.NewTestKit(t, store)
defer tk.MustExec("rollback")
se := tk.Session()
provider := initializeRepeatableReadProvider(t, tk, true)

Expand Down Expand Up @@ -139,6 +140,7 @@ func TestRepeatableReadProviderTS(t *testing.T) {
store, _, clean := testkit.CreateMockStoreAndDomain(t)
defer clean()
tk := testkit.NewTestKit(t, store)
defer tk.MustExec("rollback")
se := tk.Session()
provider := initializeRepeatableReadProvider(t, tk, true)

Expand Down Expand Up @@ -198,6 +200,7 @@ func TestRepeatableReadProviderInitialize(t *testing.T) {
defer clearScopeSettings()

tk := testkit.NewTestKit(t, store)
defer tk.MustExec("rollback")
se := tk.Session()
tk.MustExec("set @@tx_isolation = 'REPEATABLE-READ'")
tk.MustExec("set @@tidb_txn_mode='pessimistic'")
Expand Down Expand Up @@ -260,6 +263,7 @@ func TestTidbSnapshotVarInPessimisticRepeatableRead(t *testing.T) {
defer clean()

tk := testkit.NewTestKit(t, store)
defer tk.MustExec("rollback")
se := tk.Session()
tk.MustExec("set @@tx_isolation = 'REPEATABLE-READ'")
safePoint := "20160102-15:04:05 -0700"
Expand Down Expand Up @@ -477,6 +481,7 @@ func TestConflictErrorInInsertInRR(t *testing.T) {
defer clean()

tk := testkit.NewTestKit(t, store)
defer tk.MustExec("rollback")
se := tk.Session()
tk2 := testkit.NewTestKit(t, store)

Expand Down Expand Up @@ -506,8 +511,10 @@ func TestConflictErrorInPointGetForUpdateInRR(t *testing.T) {
defer clean()

tk := testkit.NewTestKit(t, store)
defer tk.MustExec("rollback")
se := tk.Session()
tk2 := testkit.NewTestKit(t, store)
defer tk2.MustExec("rollback")

tk.MustExec("use test")
tk2.MustExec("use test")
Expand Down Expand Up @@ -544,8 +551,10 @@ func TestConflictErrorInDeleteInRR(t *testing.T) {
defer clean()

tk := testkit.NewTestKit(t, store)
defer tk.MustExec("rollback")
se := tk.Session()
tk2 := testkit.NewTestKit(t, store)
defer tk2.MustExec("rollback")

tk.MustExec("use test")
tk2.MustExec("use test")
Expand Down Expand Up @@ -582,8 +591,10 @@ func TestConflictErrorInUpdateInRR(t *testing.T) {
defer clean()

tk := testkit.NewTestKit(t, store)
defer tk.MustExec("rollback")
se := tk.Session()
tk2 := testkit.NewTestKit(t, store)
defer tk2.MustExec("rollback")

tk.MustExec("use test")
tk2.MustExec("use test")
Expand Down Expand Up @@ -618,8 +629,10 @@ func TestConflictErrorInOtherQueryContainingPointGet(t *testing.T) {
defer clean()

tk := testkit.NewTestKit(t, store)
defer tk.MustExec("rollback")
se := tk.Session()
tk2 := testkit.NewTestKit(t, store)
defer tk2.MustExec("rollback")

tk.MustExec("use test")
tk2.MustExec("use test")
Expand Down
4 changes: 4 additions & 0 deletions sessiontxn/isolation/serializable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestPessimisticSerializableTxnProviderTS(t *testing.T) {
defer clean()

tk := testkit.NewTestKit(t, store)
defer tk.MustExec("rollback")
se := tk.Session()
provider := initializePessimisticSerializableProvider(t, tk)

Expand Down Expand Up @@ -75,6 +76,7 @@ func TestPessimisticSerializableTxnContextProviderLockError(t *testing.T) {
defer clean()

tk := testkit.NewTestKit(t, store)
defer tk.MustExec("rollback")
se := tk.Session()
provider := initializePessimisticSerializableProvider(t, tk)

Expand Down Expand Up @@ -116,6 +118,7 @@ func TestSerializableInitialize(t *testing.T) {
defer clearScopeSettings()

tk := testkit.NewTestKit(t, store)
defer tk.MustExec("rollback")
se := tk.Session()
tk.MustExec("set tidb_skip_isolation_level_check = 1")
tk.MustExec("set @@tx_isolation = 'SERIALIZABLE'")
Expand Down Expand Up @@ -179,6 +182,7 @@ func TestTidbSnapshotVarInSerialize(t *testing.T) {
defer clean()

tk := testkit.NewTestKit(t, store)
defer tk.MustExec("rollback")
se := tk.Session()
tk.MustExec("set tidb_skip_isolation_level_check = 1")
tk.MustExec("set @@tx_isolation = 'SERIALIZABLE'")
Expand Down

0 comments on commit 987bdd3

Please sign in to comment.