2025-07-18 15:27:22 +08:00
|
|
|
import task from 'apigo.cc/gojs/task'
|
|
|
|
import rt from 'apigo.cc/gojs/runtime'
|
|
|
|
import co from 'apigo.cc/gojs/console'
|
|
|
|
import file from 'apigo.cc/gojs/file'
|
|
|
|
import u from 'apigo.cc/gojs/util'
|
|
|
|
|
|
|
|
co.info('plugin test start')
|
|
|
|
try {
|
|
|
|
file.mkdir('testTasks/tmp')
|
2025-07-21 13:20:25 +08:00
|
|
|
task.start()
|
2025-07-18 15:27:22 +08:00
|
|
|
|
|
|
|
for (let i = 0; i < 10; i++) {
|
|
|
|
let jsFileA = 'testTasks/tmp/a' + i + '.js'
|
|
|
|
let jsFileB = 'testTasks/tmp/b' + i + '.js'
|
|
|
|
file.copy('testTasks/a.js', jsFileA)
|
|
|
|
file.copy('testTasks/b.js', jsFileB)
|
2025-07-21 13:20:25 +08:00
|
|
|
task.addTask('@every 1s', jsFileA)
|
|
|
|
task.addTask('@every 1s', jsFileB)
|
2025-07-18 15:27:22 +08:00
|
|
|
}
|
2025-07-21 13:20:25 +08:00
|
|
|
co.info('任务全部启动完成,等待任务运行')
|
2025-07-18 15:27:22 +08:00
|
|
|
rt.sleep(3000)
|
2025-07-21 13:20:25 +08:00
|
|
|
co.info('任务运行结束,正在停止任务进程')
|
2025-07-18 15:27:22 +08:00
|
|
|
task.stop()
|
|
|
|
|
|
|
|
let aStarts = task.get('aStarts')
|
|
|
|
if (aStarts !== 10) return 'aStarts(' + aStarts + ') not 10'
|
2025-07-21 13:20:25 +08:00
|
|
|
co.info('aStarts 校验通过', aStarts)
|
|
|
|
|
2025-07-18 15:27:22 +08:00
|
|
|
let aStops = task.get('aStops')
|
|
|
|
if (aStops !== 10) return 'aStops(' + aStops + ') not 10'
|
2025-07-21 13:20:25 +08:00
|
|
|
co.info('aStops 校验通过', aStops)
|
|
|
|
|
2025-07-18 15:27:22 +08:00
|
|
|
let bStarts = task.get('bStarts')
|
|
|
|
if (bStarts !== 10) return 'bStarts(' + bStarts + ') not 10'
|
2025-07-21 13:20:25 +08:00
|
|
|
co.info('bStarts 校验通过', bStarts)
|
|
|
|
|
2025-07-18 15:27:22 +08:00
|
|
|
let bStops = task.get('bStops')
|
|
|
|
if (bStops !== 10) return 'bStops(' + bStops + ') not 10'
|
2025-07-21 13:20:25 +08:00
|
|
|
co.info('bStops 校验通过', bStops)
|
|
|
|
|
2025-07-18 15:27:22 +08:00
|
|
|
let aRunTimes = task.get('aRunTimes')
|
|
|
|
if (aRunTimes !== 30) return 'aRunTimes(' + aRunTimes + ') not 30'
|
2025-07-21 13:20:25 +08:00
|
|
|
co.info('aRunTimes 校验通过', aRunTimes)
|
2025-07-18 15:27:22 +08:00
|
|
|
|
2025-07-21 13:20:25 +08:00
|
|
|
co.info('全部测试通过')
|
2025-07-18 15:27:22 +08:00
|
|
|
return true
|
|
|
|
} catch (ex) {
|
|
|
|
co.error(ex)
|
|
|
|
return false
|
|
|
|
} finally {
|
|
|
|
file.remove('testTasks/tmp')
|
|
|
|
co.info('plugin test end')
|
|
|
|
}
|