@@ -20,6 +20,10 @@ import (
20
20
"github.com/pingcap/failpoint"
21
21
"github.com/pingcap/tidb/pkg/config"
22
22
"github.com/pingcap/tidb/pkg/ddl"
23
+ "github.com/pingcap/tidb/pkg/ddl/util/callback"
24
+ "github.com/pingcap/tidb/pkg/disttask/framework/dispatcher"
25
+ "github.com/pingcap/tidb/pkg/disttask/framework/proto"
26
+ "github.com/pingcap/tidb/pkg/parser/model"
23
27
"github.com/pingcap/tidb/pkg/testkit"
24
28
"github.com/pingcap/tidb/tests/realtikvtest"
25
29
"github.com/stretchr/testify/require"
@@ -118,74 +122,73 @@ func TestAddIndexDistCancel(t *testing.T) {
118
122
tk .MustExec (`set global tidb_enable_dist_task=0;` )
119
123
}
120
124
121
- // TODO: flaky test which can't find the root cause, will run it later.
122
- // func TestAddIndexDistPauseAndResume(t *testing.T) {
123
- // store, dom := realtikvtest.CreateMockStoreAndDomainAndSetup(t)
124
- // if store.Name() != "TiKV" {
125
- // t.Skip("TiKV store only")
126
- // }
127
-
128
- // tk := testkit.NewTestKit(t, store)
129
- // tk1 := testkit.NewTestKit(t, store)
130
- // tk.MustExec("drop database if exists test;")
131
- // tk.MustExec("create database test;")
132
- // tk.MustExec("use test;")
133
-
134
- // tk.MustExec("create table t(a bigint auto_random primary key) partition by hash(a) partitions 8;")
135
- // tk.MustExec("insert into t values (), (), (), (), (), ()")
136
- // tk.MustExec("insert into t values (), (), (), (), (), ()")
137
- // tk.MustExec("insert into t values (), (), (), (), (), ()")
138
- // tk.MustExec("insert into t values (), (), (), (), (), ()")
139
- // tk.MustExec("split table t between (3) and (8646911284551352360) regions 50;")
140
-
141
- // ddl.MockDMLExecutionAddIndexSubTaskFinish = func() {
142
- // row := tk1.MustQuery("select job_id from mysql.tidb_ddl_job").Rows()
143
- // require.Equal(t, 1, len(row))
144
- // jobID := row[0][0].(string)
145
- // tk1.MustExec("admin pause ddl jobs " + jobID)
146
- // <-ddl.TestSyncChan
147
- // }
148
-
149
- // dispatcher.MockDMLExecutionOnPausedState = func(task *proto.Task) {
150
- // row := tk1.MustQuery("select job_id from mysql.tidb_ddl_job").Rows()
151
- // require.Equal(t, 1, len(row))
152
- // jobID := row[0][0].(string)
153
- // tk1.MustExec("admin resume ddl jobs " + jobID)
154
- // }
155
-
156
- // ddl.MockDMLExecutionOnTaskFinished = func() {
157
- // row := tk1.MustQuery("select job_id from mysql.tidb_ddl_job").Rows()
158
- // require.Equal(t, 1, len(row))
159
- // jobID := row[0][0].(string)
160
- // tk1.MustExec("admin pause ddl jobs " + jobID)
161
- // }
162
-
163
- // require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/ddl/mockDMLExecutionAddIndexSubTaskFinish", "3*return(true)"))
164
- // require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/disttask/framework/dispatcher/mockDMLExecutionOnPausedState", "return(true)"))
165
- // require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/ddl/syncDDLTaskPause", "return()"))
166
- // tk.MustExec(`set global tidb_enable_dist_task=1;`)
167
- // tk.MustExec("alter table t add index idx1(a);")
168
- // tk.MustExec("admin check table t;")
169
- // require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/ddl/mockDMLExecutionAddIndexSubTaskFinish"))
170
- // require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/disttask/framework/dispatcher/mockDMLExecutionOnPausedState"))
171
-
172
- // // dist task succeed, job paused and resumed.
173
- // var hook = &callback.TestDDLCallback{Do: dom}
174
- // var resumeFunc = func(job *model.Job) {
175
- // if job.IsPaused() {
176
- // row := tk1.MustQuery("select job_id from mysql.tidb_ddl_job").Rows()
177
- // require.Equal(t, 1, len(row))
178
- // jobID := row[0][0].(string)
179
- // tk1.MustExec("admin resume ddl jobs " + jobID)
180
- // }
181
- // }
182
- // hook.OnJobUpdatedExported.Store(&resumeFunc)
183
- // dom.DDL().SetHook(hook.Clone())
184
- // require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/ddl/pauseAfterDistTaskFinished", "1*return(true)"))
185
- // tk.MustExec("alter table t add index idx3(a);")
186
- // tk.MustExec("admin check table t;")
187
- // require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/ddl/pauseAfterDistTaskFinished"))
188
- // require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/ddl/syncDDLTaskPause"))
189
-
190
- // tk.MustExec(`set global tidb_enable_dist_task=0;`)
191
- // }
125
+ func TestAddIndexDistPauseAndResume (t * testing.T ) {
126
+ store , dom := realtikvtest .CreateMockStoreAndDomainAndSetup (t )
127
+ if store .Name () != "TiKV" {
128
+ t .Skip ("TiKV store only" )
129
+ }
130
+
131
+ tk := testkit .NewTestKit (t , store )
132
+ tk1 := testkit .NewTestKit (t , store )
133
+ tk .MustExec ("drop database if exists test;" )
134
+ tk .MustExec ("create database test;" )
135
+ tk .MustExec ("use test;" )
136
+
137
+ tk .MustExec ("create table t(a bigint auto_random primary key) partition by hash(a) partitions 8;" )
138
+ tk .MustExec ("insert into t values (), (), (), (), (), ()" )
139
+ tk .MustExec ("insert into t values (), (), (), (), (), ()" )
140
+ tk .MustExec ("insert into t values (), (), (), (), (), ()" )
141
+ tk .MustExec ("insert into t values (), (), (), (), (), ()" )
142
+ tk .MustExec ("split table t between (3) and (8646911284551352360) regions 50;" )
143
+
144
+ ddl .MockDMLExecutionAddIndexSubTaskFinish = func () {
145
+ row := tk1 .MustQuery ("select job_id from mysql.tidb_ddl_job" ).Rows ()
146
+ require .Equal (t , 1 , len (row ))
147
+ jobID := row [0 ][0 ].(string )
148
+ tk1 .MustExec ("admin pause ddl jobs " + jobID )
149
+ <- ddl .TestSyncChan
150
+ }
151
+
152
+ dispatcher .MockDMLExecutionOnPausedState = func (task * proto.Task ) {
153
+ row := tk1 .MustQuery ("select job_id from mysql.tidb_ddl_job" ).Rows ()
154
+ require .Equal (t , 1 , len (row ))
155
+ jobID := row [0 ][0 ].(string )
156
+ tk1 .MustExec ("admin resume ddl jobs " + jobID )
157
+ }
158
+
159
+ ddl .MockDMLExecutionOnTaskFinished = func () {
160
+ row := tk1 .MustQuery ("select job_id from mysql.tidb_ddl_job" ).Rows ()
161
+ require .Equal (t , 1 , len (row ))
162
+ jobID := row [0 ][0 ].(string )
163
+ tk1 .MustExec ("admin pause ddl jobs " + jobID )
164
+ }
165
+
166
+ require .NoError (t , failpoint .Enable ("github.com/pingcap/tidb/pkg/ddl/mockDMLExecutionAddIndexSubTaskFinish" , "3*return(true)" ))
167
+ require .NoError (t , failpoint .Enable ("github.com/pingcap/tidb/pkg/disttask/framework/dispatcher/mockDMLExecutionOnPausedState" , "return(true)" ))
168
+ require .NoError (t , failpoint .Enable ("github.com/pingcap/tidb/pkg/ddl/syncDDLTaskPause" , "return()" ))
169
+ tk .MustExec (`set global tidb_enable_dist_task=1;` )
170
+ tk .MustExec ("alter table t add index idx1(a);" )
171
+ tk .MustExec ("admin check table t;" )
172
+ require .NoError (t , failpoint .Disable ("github.com/pingcap/tidb/pkg/ddl/mockDMLExecutionAddIndexSubTaskFinish" ))
173
+ require .NoError (t , failpoint .Disable ("github.com/pingcap/tidb/pkg/disttask/framework/dispatcher/mockDMLExecutionOnPausedState" ))
174
+
175
+ // dist task succeed, job paused and resumed.
176
+ var hook = & callback.TestDDLCallback {Do : dom }
177
+ var resumeFunc = func (job * model.Job ) {
178
+ if job .IsPaused () {
179
+ row := tk1 .MustQuery ("select job_id from mysql.tidb_ddl_job" ).Rows ()
180
+ require .Equal (t , 1 , len (row ))
181
+ jobID := row [0 ][0 ].(string )
182
+ tk1 .MustExec ("admin resume ddl jobs " + jobID )
183
+ }
184
+ }
185
+ hook .OnJobUpdatedExported .Store (& resumeFunc )
186
+ dom .DDL ().SetHook (hook .Clone ())
187
+ require .NoError (t , failpoint .Enable ("github.com/pingcap/tidb/pkg/ddl/pauseAfterDistTaskFinished" , "1*return(true)" ))
188
+ tk .MustExec ("alter table t add index idx3(a);" )
189
+ tk .MustExec ("admin check table t;" )
190
+ require .NoError (t , failpoint .Disable ("github.com/pingcap/tidb/pkg/ddl/pauseAfterDistTaskFinished" ))
191
+ require .NoError (t , failpoint .Disable ("github.com/pingcap/tidb/pkg/ddl/syncDDLTaskPause" ))
192
+
193
+ tk .MustExec (`set global tidb_enable_dist_task=0;` )
194
+ }
0 commit comments