Skip to content
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

executor: close recordset again #40073

Merged
merged 5 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 13 additions & 23 deletions executor/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1095,9 +1095,7 @@ func TestCheckFailReport(t *testing.T) {
require.NoError(t, txn.Commit(tk.ctx))

ctx, hook := withLogHook(tk.ctx, t, "inconsistency")
_, err = tk.Exec(ctx, "admin check table admin_test")
require.Error(t, err)
require.Equal(t, "[admin:8223]data inconsistency in table: admin_test, index: uk1, handle: 1, index-values:\"\" != record-values:\"handle: 1, values: [KindInt64 1]\"", err.Error())
tk.MustGetErrMsg(ctx, "admin check table admin_test", "[admin:8223]data inconsistency in table: admin_test, index: uk1, handle: 1, index-values:\"\" != record-values:\"handle: 1, values: [KindInt64 1]\"")
hook.checkLogCount(t, 1)
hook.logs[0].checkMsg(t, "admin check found data inconsistency")
hook.logs[0].checkField(t,
Expand All @@ -1119,9 +1117,7 @@ func TestCheckFailReport(t *testing.T) {
require.NoError(t, txn.Commit(tk.ctx))

ctx, hook := withLogHook(tk.ctx, t, "inconsistency")
_, err = tk.Exec(ctx, "admin check table admin_test")
require.Error(t, err)
require.Equal(t, "[admin:8223]data inconsistency in table: admin_test, index: k2, handle: 1, index-values:\"\" != record-values:\"handle: 1, values: [KindString 10]\"", err.Error())
tk.MustGetErrMsg(ctx, "admin check table admin_test", "[admin:8223]data inconsistency in table: admin_test, index: k2, handle: 1, index-values:\"\" != record-values:\"handle: 1, values: [KindString 10]\"")
hook.checkLogCount(t, 1)
hook.logs[0].checkMsg(t, "admin check found data inconsistency")
hook.logs[0].checkField(t,
Expand All @@ -1143,9 +1139,8 @@ func TestCheckFailReport(t *testing.T) {
require.NoError(t, txn.Commit(tk.ctx))

ctx, hook := withLogHook(tk.ctx, t, "inconsistency")
_, err = tk.Exec(ctx, "admin check table admin_test")
require.Error(t, err)
require.Equal(t, "[admin:8223]data inconsistency in table: admin_test, index: k2, handle: 1, index-values:\"handle: 1, values: [KindString 100 KindInt64 1]\" != record-values:\"\"", err.Error())
tk.MustGetErrMsg(ctx, "admin check table admin_test",
"[admin:8223]data inconsistency in table: admin_test, index: k2, handle: 1, index-values:\"handle: 1, values: [KindString 100 KindInt64 1]\" != record-values:\"\"")
hook.checkLogCount(t, 1)
logEntry := hook.logs[0]
logEntry.checkMsg(t, "admin check found data inconsistency")
Expand Down Expand Up @@ -1188,9 +1183,8 @@ func TestCheckFailReport(t *testing.T) {
require.NoError(t, txn.Commit(tk.ctx))

ctx, hook := withLogHook(tk.ctx, t, "inconsistency")
_, err = tk.Exec(ctx, "admin check table admin_test")
require.Error(t, err)
require.Equal(t, "[admin:8223]data inconsistency in table: admin_test, index: uk1, handle: 1, index-values:\"handle: 1, values: [KindInt64 10 KindInt64 1]\" != record-values:\"\"", err.Error())
tk.MustGetErrMsg(ctx, "admin check table admin_test",
"[admin:8223]data inconsistency in table: admin_test, index: uk1, handle: 1, index-values:\"handle: 1, values: [KindInt64 10 KindInt64 1]\" != record-values:\"\"")
hook.checkLogCount(t, 1)
logEntry := hook.logs[0]
logEntry.checkMsg(t, "admin check found data inconsistency")
Expand Down Expand Up @@ -1233,9 +1227,8 @@ func TestCheckFailReport(t *testing.T) {
require.NoError(t, err)
require.NoError(t, txn.Commit(tk.ctx))
ctx, hook := withLogHook(tk.ctx, t, "inconsistency")
_, err = tk.Exec(ctx, "admin check table admin_test")
require.Error(t, err)
require.Equal(t, "[executor:8134]data inconsistency in table: admin_test, index: uk1, col: c2, handle: \"1\", index-values:\"KindInt64 20\" != record-values:\"KindInt64 10\", compare err:<nil>", err.Error())
tk.MustGetErrMsg(ctx, "admin check table admin_test",
"[executor:8134]data inconsistency in table: admin_test, index: uk1, col: c2, handle: \"1\", index-values:\"KindInt64 20\" != record-values:\"KindInt64 10\", compare err:<nil>")
hook.checkLogCount(t, 1)
logEntry := hook.logs[0]
logEntry.checkMsg(t, "admin check found data inconsistency")
Expand All @@ -1261,9 +1254,8 @@ func TestCheckFailReport(t *testing.T) {
require.NoError(t, err)
require.NoError(t, txn.Commit(tk.ctx))
ctx, hook := withLogHook(tk.ctx, t, "inconsistency")
_, err = tk.Exec(ctx, "admin check table admin_test")
require.Error(t, err)
require.Equal(t, "[executor:8134]data inconsistency in table: admin_test, index: k2, col: c3, handle: \"1\", index-values:\"KindString 200\" != record-values:\"KindString 100\", compare err:<nil>", err.Error())
tk.MustGetErrMsg(ctx, "admin check table admin_test",
"[executor:8134]data inconsistency in table: admin_test, index: k2, col: c3, handle: \"1\", index-values:\"KindString 200\" != record-values:\"KindString 100\", compare err:<nil>")
hook.checkLogCount(t, 1)
logEntry := hook.logs[0]
logEntry.checkMsg(t, "admin check found data inconsistency")
Expand Down Expand Up @@ -1301,12 +1293,10 @@ func TestCheckFailReport(t *testing.T) {

// TODO(tiancaiamao): admin check doesn't support the chunk protocol.
// Remove this after https://github.com/pingcap/tidb/issues/35156
_, err = tk.Exec(ctx, "set @@tidb_enable_chunk_rpc = off")
require.NoError(t, err)
tk.MustExec(ctx, "set @@tidb_enable_chunk_rpc = off")

_, err = tk.Exec(ctx, "admin check table admin_test")
require.Error(t, err)
require.Equal(t, `[admin:8223]data inconsistency in table: admin_test, index: uk1, handle: 282574488403969, index-values:"handle: 282574488403969, values: [KindInt64 282578800083201 KindInt64 282574488403969]" != record-values:""`, err.Error())
tk.MustGetErrMsg(ctx, "admin check table admin_test",
`[admin:8223]data inconsistency in table: admin_test, index: uk1, handle: 282574488403969, index-values:"handle: 282574488403969, values: [KindInt64 282578800083201 KindInt64 282574488403969]" != record-values:""`)
hook.checkLogCount(t, 1)
logEntry := hook.logs[0]
logEntry.checkMsg(t, "admin check found data inconsistency")
Expand Down
15 changes: 15 additions & 0 deletions testkit/asynctestkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,21 @@ func (tk *AsyncTestKit) MustExec(ctx context.Context, sql string, args ...interf
}
}

// MustGetErrMsg executes a sql statement and assert its error message.
func (tk *AsyncTestKit) MustGetErrMsg(ctx context.Context, sql string, errStr string) {
err := tk.ExecToErr(ctx, sql)
tk.require.EqualError(err, errStr)
}

// ExecToErr executes a sql statement and discard results.
func (tk *AsyncTestKit) ExecToErr(ctx context.Context, sql string, args ...interface{}) error {
res, err := tk.Exec(ctx, sql, args...)
if res != nil {
tk.require.NoError(res.Close())
}
return err
}

// MustQuery query the statements and returns result rows.
// If expected result is set it asserts the query result equals expected result.
func (tk *AsyncTestKit) MustQuery(ctx context.Context, sql string, args ...interface{}) *Result {
Expand Down