task/plugin_test.js

75 lines
2.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
})
task.start()
let jsFileC = 'testTasks/tmp/c.js'
file.copy('testTasks/c.js', jsFileC)
task.addTask('@every 1s', jsFileC)
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)
task.addTask('@every 1s', jsFileA)
task.addTask('@every 1s', jsFileB)
}
co.info('任务全部启动完成,等待任务运行')
rt.sleep(1000)
file.write(jsFileC, file.read('testTasks/c.js').replace('let runValue = 1', 'let runValue = 2'))
rt.sleep(2000)
co.info('任务运行结束,正在停止任务进程')
task.stop()
let aStarts = task.get('aStarts')
if (aStarts !== 10) return 'aStarts(' + aStarts + ') not 10'
co.info('aStarts 校验通过', aStarts)
let aStops = task.get('aStops')
if (aStops !== 10) return 'aStops(' + aStops + ') not 10'
co.info('aStops 校验通过', aStops)
let bStarts = task.get('bStarts')
if (bStarts !== 10) return 'bStarts(' + bStarts + ') not 10'
co.info('bStarts 校验通过', bStarts)
let bStops = task.get('bStops')
if (bStops !== 10) return 'bStops(' + bStops + ') not 10'
co.info('bStops 校验通过', bStops)
let aRunTimes = task.get('aRunTimes')
if (aRunTimes !== 30) return 'aRunTimes(' + aRunTimes + ') not 30'
co.info('aRunTimes 校验通过', aRunTimes)
// 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)
co.info('全部测试通过')
return true
} catch (ex) {
co.error(ex)
return false
} finally {
file.remove('testTasks/tmp')
co.info('plugin test end')
}