Skip to content

Commit

Permalink
executor: close recordset again
Browse files Browse the repository at this point in the history
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
  • Loading branch information
hawkingrei committed Dec 17, 2022
1 parent f150d37 commit 3bba9e7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
6 changes: 3 additions & 3 deletions executor/autoidtest/autoid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,7 @@ func TestAlterTableAutoIDCache(t *testing.T) {

// Note that auto_id_cache=1 use a different implementation, switch between them is not allowed.
// TODO: relax this restriction and update the test case.
_, err = tk.Exec("alter table t_473 auto_id_cache = 1")
require.Error(t, err)
tk.MustExecToErr("alter table t_473 auto_id_cache = 1")
}

func TestMockAutoIDServiceError(t *testing.T) {
Expand All @@ -762,8 +761,9 @@ func TestIssue39528(t *testing.T) {
ctx := context.Background()
var codeRun bool
ctx = context.WithValue(ctx, "testIssue39528", &codeRun)
_, err := tk.ExecWithContext(ctx, "insert into issue39528 values ()")
rs, err := tk.ExecWithContext(ctx, "insert into issue39528 values ()")
require.NoError(t, err)
// Make sure the code does not visit tikv on allocate path.
require.False(t, codeRun)
require.NoError(t, rs.Close())
}
12 changes: 6 additions & 6 deletions executor/grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ func TestGrantDBScope(t *testing.T) {
}

// Grant in wrong scope.
_, err := tk.Exec(` grant create user on test.* to 'testDB1'@'localhost';`)
err := tk.ExecToErr(` grant create user on test.* to 'testDB1'@'localhost';`)
require.True(t, terror.ErrorEqual(err, executor.ErrWrongUsage.GenWithStackByArgs("DB GRANT", "GLOBAL PRIVILEGES")))

_, err = tk.Exec("GRANT SUPER ON test.* TO 'testDB1'@'localhost';")
err = tk.ExecToErr("GRANT SUPER ON test.* TO 'testDB1'@'localhost';")
require.True(t, terror.ErrorEqual(err, executor.ErrWrongUsage.GenWithStackByArgs("DB GRANT", "NON-DB PRIVILEGES")))
}

Expand Down Expand Up @@ -168,8 +168,8 @@ func TestGrantTableScope(t *testing.T) {
require.Greater(t, strings.Index(p, mysql.Priv2SetStr[v]), -1)
}

_, err := tk.Exec("GRANT SUPER ON test2 TO 'testTbl1'@'localhost';")
require.EqualError(t, err, "[executor:1144]Illegal GRANT/REVOKE command; please consult the manual to see which privileges can be used")
tk.MustGetErrMsg("GRANT SUPER ON test2 TO 'testTbl1'@'localhost';",
"[executor:1144]Illegal GRANT/REVOKE command; please consult the manual to see which privileges can be used")
}

func TestGrantColumnScope(t *testing.T) {
Expand Down Expand Up @@ -213,8 +213,8 @@ func TestGrantColumnScope(t *testing.T) {
require.Greater(t, strings.Index(p, mysql.Priv2SetStr[v]), -1)
}

_, err := tk.Exec("GRANT SUPER(c2) ON test3 TO 'testCol1'@'localhost';")
require.EqualError(t, err, "[executor:1221]Incorrect usage of COLUMN GRANT and NON-COLUMN PRIVILEGES")
tk.MustGetErrMsg("GRANT SUPER(c2) ON test3 TO 'testCol1'@'localhost';",
"[executor:1221]Incorrect usage of COLUMN GRANT and NON-COLUMN PRIVILEGES")
}

func TestIssue2456(t *testing.T) {
Expand Down
19 changes: 6 additions & 13 deletions executor/seqtest/seq_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ func TestPrepareMaxParamCountCheck(t *testing.T) {
require.NoError(t, err)

bigSQL, bigParams := generateBatchSQL(math.MaxUint16 + 2)
_, err = tk.Exec(bigSQL, bigParams...)
err = tk.ExecToErr(bigSQL, bigParams...)
require.Error(t, err)
require.EqualError(t, err, "[executor:1390]Prepared statement contains too many placeholders")
}
Expand Down Expand Up @@ -987,16 +987,12 @@ func TestBatchInsertDelete(t *testing.T) {

// Test tidb_batch_insert could not work if enable-batch-dml is disabled.
tk.MustExec("set @@session.tidb_batch_insert=1;")
_, err = tk.Exec("insert into batch_insert (c) select * from batch_insert;")
require.Error(t, err)
require.True(t, kv.ErrTxnTooLarge.Equal(err))
tk.MustGetErrCode("insert into batch_insert (c) select * from batch_insert;", errno.ErrTxnTooLarge)
tk.MustExec("set @@session.tidb_batch_insert=0;")

// for on duplicate key
_, err = tk.Exec(`insert into batch_insert_on_duplicate select * from batch_insert_on_duplicate as tt
on duplicate key update batch_insert_on_duplicate.id=batch_insert_on_duplicate.id+1000;`)
require.Error(t, err)
require.Truef(t, kv.ErrTxnTooLarge.Equal(err), "%v", err)
tk.MustGetErrCode(`insert into batch_insert_on_duplicate select * from batch_insert_on_duplicate as tt
on duplicate key update batch_insert_on_duplicate.id=batch_insert_on_duplicate.id+1000;`, errno.ErrTxnTooLarge)
r = tk.MustQuery("select count(*) from batch_insert;")
r.Check(testkit.Rows("320"))

Expand All @@ -1022,17 +1018,14 @@ func TestBatchInsertDelete(t *testing.T) {
tk.MustExec("set @@session.tidb_dml_batch_size=50;")

// for on duplicate key
_, err = tk.Exec(`insert into batch_insert_on_duplicate select * from batch_insert_on_duplicate as tt
tk.MustExec(`insert into batch_insert_on_duplicate select * from batch_insert_on_duplicate as tt
on duplicate key update batch_insert_on_duplicate.id=batch_insert_on_duplicate.id+1000;`)
require.NoError(t, err)
r = tk.MustQuery("select count(*) from batch_insert_on_duplicate;")
r.Check(testkit.Rows("320"))

// Disable BachInsert mode in transition.
tk.MustExec("begin;")
_, err = tk.Exec("insert into batch_insert (c) select * from batch_insert;")
require.Error(t, err)
require.True(t, kv.ErrTxnTooLarge.Equal(err))
tk.MustGetErrCode("insert into batch_insert (c) select * from batch_insert;", errno.ErrTxnTooLarge)
tk.MustExec("rollback;")
r = tk.MustQuery("select count(*) from batch_insert;")
r.Check(testkit.Rows("640"))
Expand Down

0 comments on commit 3bba9e7

Please sign in to comment.