@@ -315,7 +315,7 @@ func TestTaskExecutorRun(t *testing.T) {
315315 // mock for checkBalanceSubtask, returns empty subtask list
316316 e .taskTable .EXPECT ().GetSubtasksByExecIDAndStepAndStates (gomock .Any (), "id" ,
317317 e .task1 .ID , proto .StepOne , proto .SubtaskStateRunning ).Return ([]* proto.Subtask {}, nil )
318- // this subtask is scheduled awsy during running
318+ // this subtask is scheduled away during running
319319 e .taskTable .EXPECT ().GetTaskByID (gomock .Any (), e .task1 .ID ).Return (e .task1 , nil )
320320 e .taskTable .EXPECT ().GetFirstSubtaskInStates (gomock .Any (), "id" , e .task1 .ID , proto .StepOne ,
321321 unfinishedNormalSubtaskStates ... ).Return (e .pendingSubtask1 , nil )
@@ -326,6 +326,7 @@ func TestTaskExecutorRun(t *testing.T) {
326326 <- ctx .Done ()
327327 return ctx .Err ()
328328 })
329+ e .taskExecExt .EXPECT ().IsRetryableError (gomock .Any ()).Return (true )
329330 // keep running next subtask
330331 nextSubtask := & proto.Subtask {SubtaskBase : proto.SubtaskBase {
331332 ID : 2 , Type : e .task1 .Type , Step : proto .StepOne , State : proto .SubtaskStatePending , ExecID : "id" }}
@@ -889,18 +890,17 @@ func TestCheckBalanceSubtask(t *testing.T) {
889890 // context canceled
890891 canceledCtx , cancel := context .WithCancel (ctx )
891892 cancel ()
892- taskExecutor .checkBalanceSubtask (canceledCtx )
893+ taskExecutor .checkBalanceSubtask (canceledCtx , nil )
893894 })
894895
895896 t .Run ("subtask scheduled away" , func (t * testing.T ) {
896897 mockSubtaskTable .EXPECT ().GetSubtasksByExecIDAndStepAndStates (gomock .Any (), "tidb1" ,
897898 task .ID , task .Step , proto .SubtaskStateRunning ).Return (nil , errors .New ("error" ))
898899 mockSubtaskTable .EXPECT ().GetSubtasksByExecIDAndStepAndStates (gomock .Any (), "tidb1" ,
899900 task .ID , task .Step , proto .SubtaskStateRunning ).Return ([]* proto.Subtask {}, nil )
900- runCtx , cancelCause := context .WithCancelCause (ctx )
901- taskExecutor .mu .runtimeCancel = cancelCause
901+ runCtx , cancel := context .WithCancel (ctx )
902902 require .NoError (t , runCtx .Err ())
903- taskExecutor .checkBalanceSubtask (ctx )
903+ taskExecutor .checkBalanceSubtask (ctx , cancel )
904904 require .ErrorIs (t , runCtx .Err (), context .Canceled )
905905 require .True (t , ctrl .Satisfied ())
906906 })
@@ -913,7 +913,7 @@ func TestCheckBalanceSubtask(t *testing.T) {
913913 mockExtension .EXPECT ().IsIdempotent (subtasks [0 ]).Return (false )
914914 mockSubtaskTable .EXPECT ().UpdateSubtaskStateAndError (gomock .Any (), "tidb1" ,
915915 subtasks [0 ].ID , proto .SubtaskStateFailed , ErrNonIdempotentSubtask ).Return (nil )
916- taskExecutor .checkBalanceSubtask (ctx )
916+ taskExecutor .checkBalanceSubtask (ctx , nil )
917917 require .True (t , ctrl .Satisfied ())
918918
919919 // if we failed to change state of non-idempotent subtask, will retry
@@ -930,7 +930,7 @@ func TestCheckBalanceSubtask(t *testing.T) {
930930 mockExtension .EXPECT ().IsIdempotent (subtasks [0 ]).Return (false )
931931 mockSubtaskTable .EXPECT ().UpdateSubtaskStateAndError (gomock .Any (), "tidb1" ,
932932 subtasks [0 ].ID , proto .SubtaskStateFailed , ErrNonIdempotentSubtask ).Return (nil )
933- taskExecutor .checkBalanceSubtask (ctx )
933+ taskExecutor .checkBalanceSubtask (ctx , nil )
934934 require .True (t , ctrl .Satisfied ())
935935 })
936936
@@ -945,7 +945,7 @@ func TestCheckBalanceSubtask(t *testing.T) {
945945 // used to break the loop
946946 mockSubtaskTable .EXPECT ().GetSubtasksByExecIDAndStepAndStates (gomock .Any (), "tidb1" ,
947947 task .ID , task .Step , proto .SubtaskStateRunning ).Return (nil , nil )
948- taskExecutor .checkBalanceSubtask (ctx )
948+ taskExecutor .checkBalanceSubtask (ctx , nil )
949949 require .True (t , ctrl .Satisfied ())
950950 })
951951}
0 commit comments