diff --git a/crates/lb/tests/task.lua b/crates/lb/tests/task.lua index 89d7f75..c8693ae 100644 --- a/crates/lb/tests/task.lua +++ b/crates/lb/tests/task.lua @@ -3,20 +3,26 @@ if not ok then return end describe("spawn", function() test("callback receives args", function() - spawn(function(...) - assert(select("#", ...) == 0) - end):await() + task + :spawn(function(...) + assert(select("#", ...) == 0) + end) + :await() - spawn(function(...) - assert(select("#", ...) == 1) - assert((...) == nil) - end, nil):await() + task + :spawn(function(...) + assert(select("#", ...) == 1) + assert((...) == nil) + end, nil) + :await() - spawn(function(...) - assert(select("#", ...) == 4) - local args = table.pack(...) - assert(args[1] == 1 and args[2] == 2 and args[3] == nil and args[4] == 3) - end, 1, 2, nil, 3):await() + task + :spawn(function(...) + assert(select("#", ...) == 4) + local args = table.pack(...) + assert(args[1] == 1 and args[2] == 2 and args[3] == nil and args[4] == 3) + end, 1, 2, nil, 3) + :await() end) test("await returns callback results", function() @@ -54,3 +60,15 @@ describe("spawn", function() assert(res.n == 3 and res[1] == 1 and res[2] == 3 and res[3] == nil) end) end) + +describe("sleep", function() + test("sleep is asynchronous", function() + local value + spawn(function() + value = "value" + end) + assert(value == nil) + sleep(100) -- implicit await: if it's synchronous, value wouldn't change + assert(value == "value") + end) +end)