summaryrefslogtreecommitdiff
path: root/tests/modules/async/run_jobgraph.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tests/modules/async/run_jobgraph.lua')
-rw-r--r--tests/modules/async/run_jobgraph.lua53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/modules/async/run_jobgraph.lua b/tests/modules/async/run_jobgraph.lua
new file mode 100644
index 000000000..fe53a54c6
--- /dev/null
+++ b/tests/modules/async/run_jobgraph.lua
@@ -0,0 +1,53 @@
+import("core.base.scheduler")
+import("async.jobgraph")
+import("async.runjobs")
+
+function _jobfunc(index, total, opt)
+ print("%s: run job (%d/%d)", scheduler.co_running(), index, total)
+ local dt = os.mclock()
+ os.sleep(1000)
+ dt = os.mclock() - dt
+ print("%s: run job (%d/%d) end, progress: %s, dt: %d ms", scheduler.co_running(), index, total, opt.progress, dt)
+end
+
+function _test_basic()
+ print("==================================== test basic ====================================")
+ local jobs = jobgraph.new()
+ jobs:add("job/root", _jobfunc)
+ for i = 1, 3 do
+ jobs:add("job/" .. i, _jobfunc)
+ for j = 1, 50 do
+ jobs:add("job/" .. i .. "/" .. j, _jobfunc)
+ jobs:add_orders("job/" .. i .. "/" .. j, "job/" .. i, "job/root")
+ end
+ end
+ t = os.mclock()
+ runjobs("test", jobs, {comax = 6, timeout = 1000, timer = function (running_jobs_indices)
+ print("%s: timeout (%d ms), running: %s", scheduler.co_running(), os.mclock() - t, table.concat(running_jobs_indices, ","))
+ end})
+end
+
+function _test_group()
+ print("==================================== test group ====================================")
+ local jobs = jobgraph.new()
+ jobs:add("job/root", _jobfunc)
+ for i = 1, 3 do
+ jobs:add("job/" .. i, _jobfunc, {groups = "bar"})
+ jobs:group("foo", function ()
+ for j = 1, 50 do
+ jobs:add("job/" .. i .. "/" .. j, _jobfunc)
+ end
+ end)
+ end
+ jobs:add_orders("foo", "bar", "job/root")
+ t = os.mclock()
+ runjobs("test", jobs, {comax = 6, timeout = 1000, timer = function (running_jobs_indices)
+ print("%s: timeout (%d ms), running: %s", scheduler.co_running(), os.mclock() - t, table.concat(running_jobs_indices, ","))
+ end})
+end
+
+function main()
+ _test_basic()
+ _test_group()
+end
+