Skip to content

Commit

Permalink
test: fix error checking (#59092)
Browse files Browse the repository at this point in the history
ref #57275
  • Loading branch information
D3Hunter authored Jan 21, 2025
1 parent adb8b4d commit c05646e
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions br/pkg/stream/stream_metas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2672,7 +2672,7 @@ func TestRetry(t *testing.T) {
est := MigrationExtension(s)
mg := est.MergeAndMigrateTo(ctx, 2, MMOptSkipLockingInTest())
require.Len(t, mg.Warnings, 1)
require.Error(t, mg.Warnings[0], "this disk remembers nothing")
require.ErrorContains(t, mg.Warnings[0], "this disk remembers nothing")
requireMigrationsEqual(t, mg.NewBase, mig(mDel(mN(1), lN(1), lN(2))))

mg = est.MergeAndMigrateTo(ctx, 2, MMOptSkipLockingInTest())
Expand Down Expand Up @@ -2703,7 +2703,7 @@ func TestRetryRemoveCompaction(t *testing.T) {
est := MigrationExtension(s)
mg := est.migrateTo(ctx, mig1)
require.Len(t, mg.Warnings, 1)
require.Error(t, mg.Warnings[0], "this disk will never forget")
require.ErrorContains(t, mg.Warnings[0], "this disk will never forget")
requireMigrationsEqual(t, mg.NewBase, mig(
mCompaction(placeholder(cDir(2)), placeholder(aDir(2)), 28, 32),
mTruncatedTo(27),
Expand Down
4 changes: 2 additions & 2 deletions br/pkg/streamhelper/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func testStreamListening(t *testing.T, metaCli streamhelper.AdvancerExt) {
fifth, ok := <-ch
require.True(t, ok)
require.Equal(t, fifth.Type, streamhelper.EventErr)
require.Error(t, fifth.Err, context.Canceled)
require.ErrorIs(t, fifth.Err, context.Canceled)
item, ok := <-ch
require.False(t, ok, "%v", item)
}
Expand Down Expand Up @@ -349,7 +349,7 @@ func testStreamClose(t *testing.T, metaCli streamhelper.AdvancerExt) {

third := <-ch
require.Equal(t, third.Type, streamhelper.EventErr)
require.Error(t, third.Err, io.EOF)
require.ErrorIs(t, third.Err, io.EOF)
item, ok := <-ch
require.False(t, ok, "%#v", item)
}
Expand Down
4 changes: 2 additions & 2 deletions br/pkg/task/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ func TestGetLogRangeWithFullBackupDir(t *testing.T) {
Storage: testDir,
}
_, err = getLogRange(context.TODO(), &cfg)
require.Error(t, err, errors.Annotate(berrors.ErrStorageUnknown,
"the storage has been used for full backup"))
require.ErrorIs(t, err, berrors.ErrStorageUnknown)
require.ErrorContains(t, err, "the storage has been used for full backup")
}

func TestGetLogRangeWithLogBackupDir(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion br/pkg/utils/backoff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestWithRetryReturnLastErr(t *testing.T) {
return nil
}, backoffStrategy)
require.Equal(t, 4, counter)
require.ErrorIs(t, berrors.ErrKVRangeIsEmpty, err)
require.ErrorIs(t, err, berrors.ErrKVRangeIsEmpty)
}

func TestBackoffWithFatalRawGRPCError(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/ddl/tests/tiflash/ddl_tiflash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ func TestTiFlashBatchKill(t *testing.T) {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/ddl/FastFailCheckTiFlashPendingTables"))
}()
timeOut, err := execWithTimeout(t, tk, time.Second*2000, "alter database tiflash_ddl_limit set tiflash replica 1")
require.Error(t, err, "[executor:1317]Query execution was interrupted")
require.ErrorContains(t, err, "[executor:1317]Query execution was interrupted")
require.False(t, timeOut)
wg.Wait()
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/executor/sortexec/topn_chunk_heap.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,5 @@ func TestKillSignalInTopN(t *testing.T, topnExec *TopNExec) {

topnExec.Ctx().GetSessionVars().SQLKiller.SendKillSignal(sqlkiller.QueryInterrupted)
err = topnExec.spillHelper.spillHeap(chkHeap)
require.Error(t, err, exeerrors.ErrQueryInterrupted.GenWithStackByArgs())
require.ErrorIs(t, err, exeerrors.ErrQueryInterrupted)
}
2 changes: 1 addition & 1 deletion pkg/executor/test/admintest/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,7 @@ func TestAdminCheckTableFailed(t *testing.T) {
require.NoError(t, err)
err = tk.ExecToErr("admin check table admin_test")
require.Error(t, err)
require.Error(t, err, "[admin:8223]data inconsistency in table: admin_test, index: c2, handle: 2, index-values:\"\" != record-values:\"handle: 2, values: [KindInt64 12]\"")
require.ErrorContains(t, err, "[admin:8223]data inconsistency in table: admin_test, index: c2")
tk.MustExec("set @@tidb_redact_log=1;")
err = tk.ExecToErr("admin check table admin_test")
require.Error(t, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/expression/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestGetTimeValue(t *testing.T) {
require.Equal(t, "2012-12-12 00:00:00", timeValue.String())

err = sessionVars.SetSystemVar("timestamp", "")
require.Error(t, err, "Incorrect argument type to variable 'timestamp'")
require.ErrorContains(t, err, "Incorrect argument type to variable 'timestamp'")
v, err = GetTimeValue(ctx, "2012-12-12 00:00:00", mysql.TypeTimestamp, types.MinFsp, nil)
require.NoError(t, err)

Expand Down
12 changes: 6 additions & 6 deletions pkg/expression/integration_test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3058,7 +3058,7 @@ func TestTimeBuiltin(t *testing.T) {
"period_add(0, 20)", "period_add(0, 0)", "period_add(-1, 1)", "period_add(200013, 1)", "period_add(-200012, 1)", "period_add('', '')",
} {
err := tk.QueryToErr(fmt.Sprintf("SELECT %v;", errPeriod))
require.Error(t, err, "[expression:1210]Incorrect arguments to period_add")
require.ErrorContains(t, err, "[expression:1210]Incorrect arguments to period_add")
}

// for period_diff
Expand All @@ -3070,7 +3070,7 @@ func TestTimeBuiltin(t *testing.T) {
"period_diff(-00013,1)", "period_diff(00013,1)", "period_diff(0, 0)", "period_diff(200013, 1)", "period_diff(5612, 4513)", "period_diff('', '')",
} {
err := tk.QueryToErr(fmt.Sprintf("SELECT %v;", errPeriod))
require.Error(t, err, "[expression:1210]Incorrect arguments to period_diff")
require.ErrorContains(t, err, "[expression:1210]Incorrect arguments to period_diff")
}

// TODO: fix `CAST(xx as duration)` and release the test below:
Expand Down Expand Up @@ -3844,12 +3844,12 @@ func TestSetVariables(t *testing.T) {
require.NoError(t, err)
_, err = tk.Exec("INSERT INTO tab0 select cast('999:44:33' as time);")
require.Error(t, err)
require.Error(t, err, "[types:1292]Truncated incorrect time value: '999:44:33'")
require.ErrorContains(t, err, "[types:1292]Truncated incorrect time value: '999:44:33'")
_, err = tk.Exec("set sql_mode=' ,';")
require.Error(t, err)
_, err = tk.Exec("INSERT INTO tab0 select cast('999:44:33' as time);")
require.Error(t, err)
require.Error(t, err, "[types:1292]Truncated incorrect time value: '999:44:33'")
require.ErrorContains(t, err, "[types:1292]Truncated incorrect time value: '999:44:33'")

// issue #5478
_, err = tk.Exec("set session transaction read write;")
Expand Down Expand Up @@ -3893,10 +3893,10 @@ func TestSetVariables(t *testing.T) {

_, err = tk.Exec("set @@global.max_user_connections='';")
require.Error(t, err)
require.Error(t, err, variable.ErrWrongTypeForVar.GenWithStackByArgs("max_user_connections").Error())
require.ErrorContains(t, err, variable.ErrWrongTypeForVar.GenWithStackByArgs("max_user_connections").Error())
_, err = tk.Exec("set @@global.max_prepared_stmt_count='';")
require.Error(t, err)
require.Error(t, err, variable.ErrWrongTypeForVar.GenWithStackByArgs("max_prepared_stmt_count").Error())
require.ErrorContains(t, err, variable.ErrWrongTypeForVar.GenWithStackByArgs("max_prepared_stmt_count").Error())

// Previously global values were cached. This is incorrect.
// See: https://github.com/pingcap/tidb/issues/24368
Expand Down
4 changes: 2 additions & 2 deletions pkg/owner/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func TestSetAndGetOwnerOpValue(t *testing.T) {
// test del owner key when SetOwnerOpValue
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/owner/MockDelOwnerKey", `return("delOwnerKeyAndNotOwner")`))
err = ownerMgr.SetOwnerOpValue(context.Background(), owner.OpNone)
require.Error(t, err, "put owner key failed, cmp is false")
require.ErrorContains(t, err, "put owner key failed, cmp is false")
op, err = owner.GetOwnerOpValue(context.Background(), tInfo.client, "/owner/key")
require.NotNil(t, err)
require.Equal(t, concurrency.ErrElectionNoLeader.Error(), err.Error())
Expand All @@ -241,7 +241,7 @@ func TestSetAndGetOwnerOpValue(t *testing.T) {
// And then the manager campaigns the owner again, and become the owner.
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/owner/MockDelOwnerKey", `return("onlyDelOwnerKey")`))
err = ownerMgr.SetOwnerOpValue(context.Background(), owner.OpSyncUpgradingState)
require.Error(t, err, "put owner key failed, cmp is false")
require.ErrorContains(t, err, "put owner key failed, cmp is false")
isOwner = checkOwner(ownerMgr, true)
require.True(t, isOwner)
op, err = owner.GetOwnerOpValue(context.Background(), tInfo.client, "/owner/key")
Expand Down
2 changes: 1 addition & 1 deletion pkg/planner/core/plan_cache_lru_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func TestLRUPCSetCapacity(t *testing.T) {
require.Nil(t, root)

err = lru.SetCapacity(0)
require.Error(t, err, "capacity of LRU cache should be at least 1")
require.ErrorContains(t, err, "capacity of LRU cache should be at least 1")
}

func TestIssue37914(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/table/column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,10 @@ func TestCastValue(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "utf8mb4_general_ci", val.Collation())
val, err = CastValue(ctx, types.NewBinaryLiteralDatum([]byte{0xE5, 0xA5, 0xBD, 0x81}), &colInfoS, false, false)
require.Error(t, err, "[table:1366]Incorrect string value '\\x81' for column ''")
require.ErrorContains(t, err, "[table:1366]Incorrect string value '\\x81' for column ''")
require.Equal(t, "utf8mb4_general_ci", val.Collation())
val, err = CastValue(ctx, types.NewDatum([]byte{0xE5, 0xA5, 0xBD, 0x81}), &colInfoS, false, false)
require.Error(t, err, "[table:1366]Incorrect string value '\\x81' for column ''")
require.ErrorContains(t, err, "[table:1366]Incorrect string value '\\x81' for column ''")
require.Equal(t, "utf8mb4_general_ci", val.Collation())
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/table/temptable/interceptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func TestGetSessionTemporaryTableKey(t *testing.T) {

// test normal table should not be allowed
val, err = getSessionKey(ctx, normalTb.Meta(), retriever, encodeTableKey(1))
require.Error(t, err, "Cannot get normal table key from session")
require.ErrorContains(t, err, "Cannot get normal table key from session")
require.Nil(t, val)
require.Equal(t, 0, len(retriever.GetInvokes()))

Expand Down

0 comments on commit c05646e

Please sign in to comment.