Skip to content

Commit 1c078a0

Browse files
authored
ddl: make test TestRenameTableAutoIDs more stable (#54695)
close #53765
1 parent 26378cb commit 1c078a0

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

pkg/ddl/schema_test.go

+18-4
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ func testCheckJobCancelled(t *testing.T, store kv.Storage, job *model.Job, state
372372
}
373373

374374
func TestRenameTableAutoIDs(t *testing.T) {
375-
store := testkit.CreateMockStore(t)
375+
store, dom := testkit.CreateMockStoreAndDomain(t)
376376
tk1 := testkit.NewTestKit(t, store)
377377
tk2 := testkit.NewTestKit(t, store)
378378
tk3 := testkit.NewTestKit(t, store)
@@ -396,6 +396,7 @@ func TestRenameTableAutoIDs(t *testing.T) {
396396
if len(res) == 1 && res[0][col] == s {
397397
break
398398
}
399+
399400
logutil.DDLLogger().Info("Could not find match", zap.String("tableName", tableName), zap.String("s", s), zap.Int("colNum", col))
400401

401402
for i := range res {
@@ -412,19 +413,32 @@ func TestRenameTableAutoIDs(t *testing.T) {
412413
tk2.MustExec(`set @@session.innodb_lock_wait_timeout = 0`)
413414
tk2.MustExec(`BEGIN`)
414415
tk2.MustExec(`insert into t values (null, 4)`)
416+
417+
v1 := dom.InfoSchema().SchemaMetaVersion()
418+
415419
go func() {
416420
alterChan <- tk1.ExecToErr(`rename table t to ` + dbName + `2.t2`)
417421
}()
418422
waitFor(11, "t", "running")
419423
waitFor(4, "t", "public")
424+
425+
// ddl finish does not mean the infoschema loaded.
426+
// when infoschema v1->v2 switch, it take more time, so we must wait to ensure
427+
// the new infoschema is used.
428+
require.Eventually(t, func() bool { return dom.InfoSchema().SchemaMetaVersion() > v1 }, time.Minute, 2*time.Millisecond)
429+
420430
tk3.MustExec(`BEGIN`)
421431
tk3.MustExec(`insert into ` + dbName + `2.t2 values (50, 5)`)
422-
432+
// TODO: still unstable here.
433+
// This is caused by a known rename table and autoid compatibility issue.
434+
// In the past we try to fix it by the same auto id allocator before and after table renames.
435+
// https://github.com/pingcap/tidb/pull/47892
436+
// But during infoschema v1->v2 switch, infoschema full load happen, then both the old and new
437+
// autoid instance exists. tk2 here use the old autoid allocator, cause txn conflict on index key
438+
// b=20, conflicting with the next line insert values (20, 5)
423439
tk2.MustExec(`insert into t values (null, 6)`)
424440
tk3.MustExec(`insert into ` + dbName + `2.t2 values (20, 5)`)
425-
426441
// Done: Fix https://github.com/pingcap/tidb/issues/46904
427-
//tk2.MustContainErrMsg(`insert into t values (null, 6)`, "[tikv:1205]Lock wait timeout exceeded; try restarting transaction")
428442
tk2.MustExec(`insert into t values (null, 6)`)
429443
tk3.MustExec(`insert into ` + dbName + `2.t2 values (null, 7)`)
430444
tk2.MustExec(`COMMIT`)

0 commit comments

Comments
 (0)