Files
jx-callback/business/jxutils/tasksch/task_man_test.go
gazebo 81089fb85c - category sync almost ok.
- refactor tasksch (isContinueWhenError)
2018-09-22 10:26:31 +08:00

50 lines
1.6 KiB
Go

package tasksch
import (
"math/rand"
"testing"
"time"
"git.rosy.net.cn/baseapi/utils"
)
func TestTaskMan(t *testing.T) {
itemList := make([]int, 100)
for k := range itemList {
itemList[k] = k
}
task1 := RunManagedTask("test", false, func(taskName string, result []interface{}, err error) {
// t.Log("finished here")
// t.Log(utils.Format4Output(result, false))
}, 100, 7, "autotest", func(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)
}
return retSlice, nil
}, itemList, "a", "b", 1, 2)
task2 := RunManagedTask("test", false, func(taskName string, result []interface{}, err error) {
// t.Log("finished here")
// t.Log(utils.Format4Output(result, false))
}, 100, 7, "autotest", func(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)
}
return retSlice, nil
}, itemList, "a", "b", 1, 2)
time.Sleep(2 * time.Second)
task2.Cancel()
if task1.GetStatus() == task2.GetStatus() {
t.Log(utils.Format4Output(GetTasks("", TaskStatusBegin, TaskStatusEnd, 5), false))
t.Fatal("status should not be same")
}
}