- when IsContinueWhenError is true, if partial failed, mark the whole task as failed.

This commit is contained in:
gazebo
2018-10-27 18:00:02 +08:00
parent 0743df73b2
commit 7a93cf745d
4 changed files with 56 additions and 12 deletions

View File

@@ -65,3 +65,38 @@ func TestCancelParallelTask(t *testing.T) {
}
// t.Log(utils.Format4Output(result, false))
}
func TestRunParallelTaskPartialSuccess(t *testing.T) {
itemList := make([]int, 100)
for k := range itemList {
itemList[k] = k
}
task := NewParallelTask("test", NewParallelConfig().SetParallelCount(100).SetBatchSize(7).SetIsContinueWhenError(true), "autotest", func(task *ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
sleepSecond := rand.Intn(5)
t.Logf("sleep %d seconds", sleepSecond)
time.Sleep(time.Duration(sleepSecond) * time.Second)
retSlice := make([]string, len(batchItemList))
for k := range retSlice {
retSlice[k] = "hello:" + utils.Int2Str(batchItemList[k].(int)*2)
}
if rand.Intn(2) == 1 {
return nil, fmt.Errorf("test:%d", batchItemList[0].(int))
}
return retSlice, nil
}, itemList, "a", "b", 1, 2)
task.Run()
result, err := task.GetResult(1 * time.Microsecond)
if err == nil || task.GetStatus() != TaskStatusWorking {
t.Fatal("task can not be done in 1 microsecond")
}
result, err = task.GetResult(0)
if err == nil {
t.Fatal("不应该全部成功")
}
fmt.Println(err)
if len(result) == len(itemList) {
t.Log(utils.Format4Output(result, false))
t.Fatal("不应该全部成功")
}
t.Log(task.GetStatus())
}