@@ -204,8 +204,21 @@ func cancelSuccess(rs *testkit.Result) bool {
204
204
return strings .Contains (rs .Rows ()[0 ][1 ].(string ), "success" )
205
205
}
206
206
207
+ << << << < HEAD
207
208
func TestCancel (t * testing.T ) {
208
209
store , dom := testkit .CreateMockStoreAndDomainWithSchemaLease (t , 100 * time .Millisecond )
210
+ == == == =
211
+ func TestCancelVariousJobs (t * testing .T ) {
212
+ var enterCnt , exitCnt atomic.Int32
213
+ testfailpoint .EnableCall (t , "github.com/pingcap/tidb/pkg/ddl/beforeDeliveryJob" , func (job * model.Job ) { enterCnt .Add (1 ) })
214
+ testfailpoint .EnableCall (t , "github.com/pingcap/tidb/pkg/ddl/afterDeliveryJob" , func (job * model.JobW ) { exitCnt .Add (1 ) })
215
+ waitDDLWorkerExited := func () {
216
+ require .Eventually (t , func () bool {
217
+ return enterCnt .Load () == exitCnt .Load ()
218
+ }, 10 * time .Second , 10 * time .Millisecond )
219
+ }
220
+ store := testkit .CreateMockStoreWithSchemaLease (t , 100 * time .Millisecond , mockstore .WithMockTiFlash (2 ))
221
+ >> >> >> > 46 aa33bb9d2 (ddl : fix job state overridden when concurrent updates don 't overlap in time range (#58495 ))
209
222
tk := testkit .NewTestKit (t , store )
210
223
tkCancel := testkit .NewTestKit (t , store )
211
224
@@ -352,6 +365,7 @@ func TestCancelForAddUniqueIndex(t *testing.T) {
352
365
require .Equal (t , 0 , len (tbl .Meta ().Indices ))
353
366
}
354
367
368
+ << << << < HEAD
355
369
func TestSubmitJobAfterDDLIsClosed (t * testing.T ) {
356
370
store , dom := testkit .CreateMockStoreAndDomain (t , mockstore .WithStoreType (mockstore .EmbedUnistore ))
357
371
tk := testkit .NewTestKit (t , store )
@@ -365,4 +379,27 @@ func TestSubmitJobAfterDDLIsClosed(t *testing.T) {
365
379
require .NoError (t , err )
366
380
require .Error (t , ddlErr )
367
381
require .Equal (t , "context canceled" , ddlErr .Error ())
382
+ == == == =
383
+ func TestCancelJobBeforeRun (t * testing .T ) {
384
+ store := testkit .CreateMockStore (t )
385
+ tk := testkit .NewTestKit (t , store )
386
+ tkCancel := testkit .NewTestKit (t , store )
387
+
388
+ // Prepare schema.
389
+ tk .MustExec ("use test" )
390
+ tk .MustExec (`create table t (c1 int, c2 int, c3 int)` )
391
+ tk .MustExec ("insert into t values(1, 1, 1)" )
392
+ tk .MustQuery ("select * from t" ).Check (testkit .Rows ("1 1 1" ))
393
+
394
+ counter := 0
395
+ testfailpoint .EnableCall (t , "github.com/pingcap/tidb/pkg/ddl/beforeTransitOneJobStep" , func (jobW * model.JobW ) {
396
+ if counter == 0 && jobW .TableName == "t" {
397
+ tkCancel .MustExec (fmt .Sprintf ("admin cancel ddl jobs %d" , jobW .ID ))
398
+ counter ++
399
+ }
400
+ })
401
+
402
+ tk .MustGetErrCode ("truncate table t" , errno .ErrCancelledDDLJob )
403
+ tk .MustQuery ("select * from t" ).Check (testkit .Rows ("1 1 1" ))
404
+ >> >> >> > 46 aa33bb9d2 (ddl : fix job state overridden when concurrent updates don 't overlap in time range (#58495 ))
368
405
}
0 commit comments