Skip to content

Commit

Permalink
VTGate: Update txn_rollback_shutdown_test.go to actually assert trans…
Browse files Browse the repository at this point in the history
…action rollback

Signed-off-by: Brendan Dougherty <[email protected]>
  • Loading branch information
brendar committed Sep 24, 2024
1 parent 83b37b8 commit 9ef4340
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,27 +98,26 @@ func TestTransactionRollBackWhenShutDown(t *testing.T) {

// start an incomplete transaction
utils.Exec(t, conn, "begin")
utils.Exec(t, conn, "insert into buffer(id, msg) values(33,'mark')")
utils.Exec(t, conn, "select * from buffer where id = 3 for update")

// Enforce a restart to enforce rollback
if err = clusterInstance.RestartVtgate(); err != nil {
t.Errorf("Fail to re-start vtgate: %v", err)
}

want := ""

// Make a new mysql connection to vtGate
vtParams = clusterInstance.GetVTParams(keyspaceName)
conn2, err := mysql.Connect(ctx, &vtParams)
require.NoError(t, err)
defer conn2.Close()

vtParams = clusterInstance.GetVTParams(keyspaceName)
// Verify that rollback worked
qr := utils.Exec(t, conn2, "select id from buffer where msg='mark'")
got := fmt.Sprintf("%v", qr.Rows)
want = `[[INT64(3)]]`
assert.Equal(t, want, got)
// Start a new transaction
utils.Exec(t, conn2, "begin")
defer utils.Exec(t, conn2, "rollback")
// Verify previous transaction was rolled back. Row lock should be available, otherwise we'll get an error.
qr := utils.Exec(t, conn2, "select * from buffer where id = 3 for update nowait")
assert.Equal(t, 1, len(qr.Rows))

}

func TestErrorInAutocommitSession(t *testing.T) {
Expand Down

0 comments on commit 9ef4340

Please sign in to comment.