task/plugin_test.js

45 lines
1.3 KiB
JavaScript
Raw Permalink 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.asyncStart()
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.newTask('@every 1s', jsFileA)
task.newTask('@every 1s', jsFileB)
}
rt.sleep(3000)
task.stop()
let aStarts = task.get('aStarts')
if (aStarts !== 10) return 'aStarts(' + aStarts + ') not 10'
let aStops = task.get('aStops')
if (aStops !== 10) return 'aStops(' + aStops + ') not 10'
let bStarts = task.get('bStarts')
if (bStarts !== 10) return 'bStarts(' + bStarts + ') not 10'
let bStops = task.get('bStops')
if (bStops !== 10) return 'bStops(' + bStops + ') not 10'
let aRunTimes = task.get('aRunTimes')
if (aRunTimes !== 30) return 'aRunTimes(' + aRunTimes + ') not 30'
co.info()
return true
} catch (ex) {
co.error(ex)
return false
} finally {
file.remove('testTasks/tmp')
co.info('plugin test end')
}