Add sleep test
This commit is contained in:
parent
503985269a
commit
72b3afaeea
@ -3,20 +3,26 @@ if not ok then return end
|
|||||||
|
|
||||||
describe("spawn", function()
|
describe("spawn", function()
|
||||||
test("callback receives args", function()
|
test("callback receives args", function()
|
||||||
spawn(function(...)
|
task
|
||||||
|
:spawn(function(...)
|
||||||
assert(select("#", ...) == 0)
|
assert(select("#", ...) == 0)
|
||||||
end):await()
|
end)
|
||||||
|
:await()
|
||||||
|
|
||||||
spawn(function(...)
|
task
|
||||||
|
:spawn(function(...)
|
||||||
assert(select("#", ...) == 1)
|
assert(select("#", ...) == 1)
|
||||||
assert((...) == nil)
|
assert((...) == nil)
|
||||||
end, nil):await()
|
end, nil)
|
||||||
|
:await()
|
||||||
|
|
||||||
spawn(function(...)
|
task
|
||||||
|
:spawn(function(...)
|
||||||
assert(select("#", ...) == 4)
|
assert(select("#", ...) == 4)
|
||||||
local args = table.pack(...)
|
local args = table.pack(...)
|
||||||
assert(args[1] == 1 and args[2] == 2 and args[3] == nil and args[4] == 3)
|
assert(args[1] == 1 and args[2] == 2 and args[3] == nil and args[4] == 3)
|
||||||
end, 1, 2, nil, 3):await()
|
end, 1, 2, nil, 3)
|
||||||
|
:await()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
test("await returns callback results", function()
|
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)
|
assert(res.n == 3 and res[1] == 1 and res[2] == 3 and res[3] == nil)
|
||||||
end)
|
end)
|
||||||
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user