From 3a7f2366e463bfb93a7b30988c087b195d99f143 Mon Sep 17 00:00:00 2001 From: luaneko Date: Fri, 27 Jun 2025 04:29:11 +1000 Subject: [PATCH] Ensure spawn order is consistent --- crates/lb/tests/task.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/crates/lb/tests/task.lua b/crates/lb/tests/task.lua index aa33507..5cd0843 100644 --- a/crates/lb/tests/task.lua +++ b/crates/lb/tests/task.lua @@ -45,6 +45,26 @@ describe("spawn", function() end, 5, 4, nil, 3, nil):await()) assert(res.n == 3 and res[1] == 1 and res[2] == 3 and res[3] == nil) end) + + test("order is consistent", function() + -- all tasks spawned in one batch should be resumed in the spawn order + local tasks, nums = {}, {} + for i = 1, 10 do + table.insert( + tasks, + spawn(function() + table.insert(nums, i) + end) + ) + end + for i = 10, 1, -1 do + tasks[i]:await() + end + assert(#nums == 10) + for i = 1, 10 do + assert(nums[i] == i) + end + end) end) describe("sleep", function()