diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/modules/os/async_copy.lua | 34 | ||||
| -rw-r--r-- | tests/modules/os/async_scheduler.lua | 39 |
2 files changed, 73 insertions, 0 deletions
diff --git a/tests/modules/os/async_copy.lua b/tests/modules/os/async_copy.lua new file mode 100644 index 000000000..751a940ae --- /dev/null +++ b/tests/modules/os/async_copy.lua @@ -0,0 +1,34 @@ +local function _prepare_source(dir) + os.mkdir(dir) + io.writefile(path.join(dir, "foo.txt"), "foo") + io.writefile(path.join(dir, "bar.txt"), "bar") +end + +function main() + local root = os.tmpfile() .. ".os_async_copy" + local srcdir = path.join(root, "src") + local dstdir = path.join(root, "dst") + + _prepare_source(srcdir) + print("source prepared: %s", srcdir) + + local files = os.files(path.join(srcdir, "*.txt"), {async = true}) + assert(files and #files == 2) + print("async enumerate: %d files", #files) + + os.cp(srcdir, dstdir, {async = true}) + assert(os.isdir(dstdir)) + print("async copy done: %s", dstdir) + + files = os.files(path.join(dstdir, "*.txt"), {async = true}) + assert(files and #files == 2) + + os.rm(dstdir, {async = true}) + assert(not os.isdir(dstdir)) + print("dst removed async") + + os.rm(srcdir, {async = true}) + os.tryrm(root) + print("async copy test finished") +end + 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 + |
