@@ -203,6 +203,36 @@ func (c *testCallback) OnJobRunBefore(job *model.Job) {
203
203
}
204
204
}
205
205
206
+ func TestAddIndexGetChunkCancel (t * testing.T ) {
207
+ store := testkit .CreateMockStore (t )
208
+ tk := testkit .NewTestKit (t , store )
209
+ tk .MustExec ("use test;" )
210
+ defer ingesttestutil .InjectMockBackendCtx (t , store )()
211
+
212
+ tk .MustExec ("create table t (a int primary key, b int);" )
213
+ for i := range 100 {
214
+ tk .MustExec (fmt .Sprintf ("insert into t values (%d, %d);" , i * 10000 , i * 10000 ))
215
+ }
216
+ tk .MustExec ("split table t between (0) and (1000000) regions 10;" )
217
+ jobID := int64 (0 )
218
+ testfailpoint .EnableCall (t , "github.com/pingcap/tidb/pkg/ddl/beforeRunOneJobStep" , func (job * model.Job ) {
219
+ if jobID == 0 && job .Type == model .ActionAddIndex {
220
+ jobID = job .ID
221
+ }
222
+ })
223
+ cancelled := false
224
+ testfailpoint .EnableCall (t , "github.com/pingcap/tidb/pkg/ddl/beforeGetChunk" , func () {
225
+ if ! cancelled {
226
+ tk2 := testkit .NewTestKit (t , store )
227
+ tk2 .MustExec (fmt .Sprintf ("admin cancel ddl jobs %d" , jobID ))
228
+ cancelled = true
229
+ }
230
+ })
231
+ tk .MustGetErrCode ("alter table t add index idx(b);" , errno .ErrCancelledDDLJob )
232
+ require .True (t , cancelled )
233
+ tk .MustExec ("admin check table t;" )
234
+ }
235
+
206
236
func TestIngestPartitionRowCount (t * testing.T ) {
207
237
store := testkit .CreateMockStore (t )
208
238
tk := testkit .NewTestKit (t , store )
0 commit comments