From ea7a37c66c1325d8a301e4b391261e0ac5417d23 Mon Sep 17 00:00:00 2001 From: tangenta Date: Sun, 26 Mar 2023 21:20:43 +0800 Subject: [PATCH] ddl: fix unstable test TestAddIndexUniqueFailOnDuplicate (#42589) close pingcap/tidb#42417 --- ddl/index_modify_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ddl/index_modify_test.go b/ddl/index_modify_test.go index 2caf54c31c157..0bd49e7d6cbdf 100644 --- a/ddl/index_modify_test.go +++ b/ddl/index_modify_test.go @@ -1069,17 +1069,19 @@ func TestAddIndexWithDupIndex(t *testing.T) { } func TestAddIndexUniqueFailOnDuplicate(t *testing.T) { - ddl.ResultCounterForTest = &atomic.Int32{} store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) tk.MustExec("use test") tk.MustExec("create table t (a bigint primary key clustered, b int);") + // The subtask execution order is not guaranteed in distributed reorg. We need to disable it first. + tk.MustExec("set @@global.tidb_enable_dist_task = 0;") tk.MustExec("set @@global.tidb_ddl_reorg_worker_cnt = 1;") for i := 1; i <= 12; i++ { tk.MustExec("insert into t values (?, ?)", i, i) } tk.MustExec("insert into t values (0, 1);") // Insert a duplicate key. tk.MustQuery("split table t by (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12);").Check(testkit.Rows("13 1")) + ddl.ResultCounterForTest = &atomic.Int32{} tk.MustGetErrCode("alter table t add unique index idx (b);", errno.ErrDupEntry) require.Less(t, int(ddl.ResultCounterForTest.Load()), 6) ddl.ResultCounterForTest = nil