summaryrefslogtreecommitdiff
path: root/tests/modules/async
diff options
context:
space:
mode:
authorruki <[email protected]>2025-03-14 00:53:08 +0800
committerruki <[email protected]>2025-04-08 15:31:54 +0800
commit00ebba39f7e81d2b52bfb3be458f9825e6d7c070 (patch)
tree007f7015fbb0720238b694c62216cace9e9d44ab /tests/modules/async
parent3a813e0ede0505a32ef9e4da7faeb792db0c40f3 (diff)
add jobgraph stub
Diffstat (limited to 'tests/modules/async')
-rw-r--r--tests/modules/async/jobgraph.lua7
-rw-r--r--tests/modules/async/runjobs.lua43
2 files changed, 50 insertions, 0 deletions
diff --git a/tests/modules/async/jobgraph.lua b/tests/modules/async/jobgraph.lua
new file mode 100644
index 000000000..dd8cb05f8
--- /dev/null
+++ b/tests/modules/async/jobgraph.lua
@@ -0,0 +1,7 @@
+import("core.base.scheduler")
+import("async.jobgraph")
+
+function main()
+
+end
+
diff --git a/tests/modules/async/runjobs.lua b/tests/modules/async/runjobs.lua
new file mode 100644
index 000000000..4e2a98cc0
--- /dev/null
+++ b/tests/modules/async/runjobs.lua
@@ -0,0 +1,43 @@
+import("core.base.scheduler")
+import("private.async.jobpool")
+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 main()
+
+ -- test callback
+ print("==================================== test callback ====================================")
+ local t = os.mclock()
+ runjobs("test", _jobfunc, {total = 100, 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})
+
+ -- test jobs
+ print("==================================== test jobs ====================================")
+ local jobs = jobpool.new()
+ local root = jobs:addjob("job/root", function (index, total, opt)
+ _jobfunc(index, total, opt)
+ end)
+ for i = 1, 3 do
+ local job = jobs:addjob("job/" .. i, function (index, total, opt)
+ _jobfunc(index, total, opt)
+ end, {rootjob = root})
+ for j = 1, 50 do
+ jobs:addjob("job/" .. i .. "/" .. j, function (index, total, opt)
+ _jobfunc(index, total, opt)
+ end, {rootjob = job})
+ 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
+