summaryrefslogtreecommitdiff
path: root/tests/modules/os/async_scheduler.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2025-11-08 00:48:23 +0800
committerruki <[email protected]>2025-11-08 00:48:23 +0800
commita9567b1b432e8f2d352963f66bde3cf07b863c5a (patch)
treed0100cfea439a72de0e0c1494e4c5d2551e0e43d /tests/modules/os/async_scheduler.lua
parent45f03066b9738062aaa512de7c1c9f0e7c096ec4 (diff)
add tests
Diffstat (limited to 'tests/modules/os/async_scheduler.lua')
-rw-r--r--tests/modules/os/async_scheduler.lua39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/modules/os/async_scheduler.lua b/tests/modules/os/async_scheduler.lua
new file mode 100644
index 000000000..d6818c9c5
--- /dev/null
+++ b/tests/modules/os/async_scheduler.lua
@@ -0,0 +1,39 @@
+import("core.base.scheduler")
+
+local function _prepare_workspace(root)
+ os.mkdir(root)
+ for idx = 1, 4 do
+ io.writefile(path.join(root, string.format("file%d.txt", idx)), "xmake")
+ end
+end
+
+function main()
+ local root = os.tmpfile() .. ".os_async_sched"
+ _prepare_workspace(root)
+ print("workspace prepared: %s", root)
+
+ local group = "os_async_scheduler"
+ scheduler.co_group_begin(group, function ()
+ for idx = 1, 4 do
+ scheduler.co_start(function ()
+ local matches = os.files(path.join(root, string.format("file%d.txt", idx)), {async = true})
+ assert(matches and #matches == 1)
+ print("async match %d finished", idx)
+ end)
+ end
+
+ scheduler.co_start(function ()
+ local copydir = root .. "_copy"
+ os.cp(root, copydir, {async = true})
+ assert(os.isdir(copydir))
+ os.rm(copydir, {async = true})
+ print("async copy complete: %s", copydir)
+ end)
+ end)
+
+ scheduler.co_group_wait(group)
+ print("all async tasks finished")
+ os.rm(root, {async = true})
+ print("async scheduler test finished")
+end
+