@@ -229,6 +229,36 @@ func (c *testCallback) OnJobRunBefore(job *model.Job) {
229
229
}
230
230
}
231
231
232
+ func TestAddIndexGetChunkCancel (t * testing.T ) {
233
+ store := testkit .CreateMockStore (t )
234
+ tk := testkit .NewTestKit (t , store )
235
+ tk .MustExec ("use test;" )
236
+ defer ingesttestutil .InjectMockBackendCtx (t , store )()
237
+
238
+ tk .MustExec ("create table t (a int primary key, b int);" )
239
+ for i := range 100 {
240
+ tk .MustExec (fmt .Sprintf ("insert into t values (%d, %d);" , i * 10000 , i * 10000 ))
241
+ }
242
+ tk .MustExec ("split table t between (0) and (1000000) regions 10;" )
243
+ jobID := int64 (0 )
244
+ testfailpoint .EnableCall (t , "github.com/pingcap/tidb/pkg/ddl/beforeRunOneJobStep" , func (job * model.Job ) {
245
+ if jobID == 0 && job .Type == model .ActionAddIndex {
246
+ jobID = job .ID
247
+ }
248
+ })
249
+ cancelled := false
250
+ testfailpoint .EnableCall (t , "github.com/pingcap/tidb/pkg/ddl/beforeGetChunk" , func () {
251
+ if ! cancelled {
252
+ tk2 := testkit .NewTestKit (t , store )
253
+ tk2 .MustExec (fmt .Sprintf ("admin cancel ddl jobs %d" , jobID ))
254
+ cancelled = true
255
+ }
256
+ })
257
+ tk .MustGetErrCode ("alter table t add index idx(b);" , errno .ErrCancelledDDLJob )
258
+ require .True (t , cancelled )
259
+ tk .MustExec ("admin check table t;" )
260
+ }
261
+
232
262
func TestIngestPartitionRowCount (t * testing.T ) {
233
263
store := testkit .CreateMockStore (t )
234
264
tk := testkit .NewTestKit (t , store )
0 commit comments