task/plugin_test.js

75 lines
2.4 KiB
JavaScript
Raw Normal View History

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')
task.config({
hotLoad: 1
})
2025-07-21 13:20:25 +08:00
task.start()
2025-07-18 15:27:22 +08:00
let jsFileC = 'testTasks/tmp/c.js'
file.copy('testTasks/c.js', jsFileC)
task.addTask('@every 1s', jsFileC)
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('任务全部启动完成,等待任务运行')
rt.sleep(1000)
file.write(jsFileC, file.read('testTasks/c.js').replace('let runValue = 1', 'let runValue = 2'))
rt.sleep(2000)
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
// c 重新加载过前2次1后1次2
let cStarts = task.get('cStarts')
if (cStarts !== 3) return 'cStarts(' + cStarts + ') not 3'
co.info('cStarts 校验通过', cStarts)
let cStops = task.get('cStops')
if (cStops !== 3) return 'cStops(' + cStops + ') not 3'
co.info('cStops 校验通过', cStops)
let cTag = task.get('cTag')
if (cTag !== 4) return 'cTag(' + cTag + ') not 4'
co.info('cTag 校验通过', cTag)
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')
}