From bfdc7a92c4e3e99522abb6d90ef2cbb021f36fc8 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Thu, 5 Jun 2025 16:03:22 +0200 Subject: Change lane:join() return values * when no error is raised in the lane, lane:join() now precedes the lane returned values with true * lane body is no longer forced to return something when used with join() * adjusted all relevant unit tests accordingly --- unit_tests/scripts/coro/basics.lua | 6 ++++-- unit_tests/scripts/lane/tasking_join_test.lua | 16 +++++++++++----- unit_tests/scripts/linda/wake_period.lua | 5 +++-- 3 files changed, 18 insertions(+), 9 deletions(-) (limited to 'unit_tests/scripts') diff --git a/unit_tests/scripts/coro/basics.lua b/unit_tests/scripts/coro/basics.lua index cd2f410..c0b7a36 100644 --- a/unit_tests/scripts/coro/basics.lua +++ b/unit_tests/scripts/coro/basics.lua @@ -85,7 +85,8 @@ if true then assert(h3:resume(1) == nil) -- similarly, we can get them with join() - assert(h3:join() == "world" and h3.status == "suspended") + local r3, ret3 = h3:join() + assert(r3 == true and ret3 == "world" and h3.status == "suspended") -- since we consumed the returned values, they should not be here when we resume assert(h3:resume(2) == nil) @@ -93,5 +94,6 @@ if true then assert(h3:resume(3) == "!") -- the final return value of the lane body remains to be read - assert(h3:join() == "done!" and h3.status == "done") + local r3, ret3 = h3:join() + assert(r3 == true and ret3 == "done!" and h3.status == "done") end diff --git a/unit_tests/scripts/lane/tasking_join_test.lua b/unit_tests/scripts/lane/tasking_join_test.lua index 2fbce6c..495a709 100644 --- a/unit_tests/scripts/lane/tasking_join_test.lua +++ b/unit_tests/scripts/lane/tasking_join_test.lua @@ -30,14 +30,19 @@ end PRINT("---=== :join test ===---", "\n\n") +-- a lane body that returns nothing is successfully joined with true, nil +local r, ret = lanes_gen(function() end)():join() +assert(r == true and ret == nil) + -- NOTE: 'unpack()' cannot be used on the lane handle; it will always return nil -- (unless [1..n] has been read earlier, in which case it would seemingly -- work). -local S= lanes_gen("table", { name = 'auto', gc_cb = gc_cb }, +local S = lanes_gen("table", { name = 'auto', gc_cb = gc_cb }, function(arg) lane_threadname "join test lane" set_finalizer(function() end) + -- take arg table, reverse its contents in aux, then return the unpacked result local aux= {} for i, v in ipairs(arg) do table.insert(aux, 1, v) @@ -46,15 +51,16 @@ local S= lanes_gen("table", { name = 'auto', gc_cb = gc_cb }, return (unpack or table.unpack)(aux) end) -h= S { 12, 13, 14 } -- execution starts, h[1..3] will get the return values +local h = S { 12, 13, 14 } -- execution starts, h[1..3] will get the return values -- wait a bit so that the lane has a chance to set its debug name SLEEP(0.5) print("joining with '" .. h:get_threadname() .. "'") -local a,b,c,d= h:join() +local r, a, b, c, d = h:join() if h.status == "error" then - print(h:get_threadname(), "error: " , a, b, c, d) + print(h:get_threadname(), "error: " , r, a, b, c, d) else - print(h:get_threadname(), a,b,c,d) + print(h:get_threadname(), r, a, b, c, d) + assert(r==true, "r == " .. tostring(r)) assert(a==14, "a == " .. tostring(a)) assert(b==13, "b == " .. tostring(b)) assert(c==12, "c == " .. tostring(c)) diff --git a/unit_tests/scripts/linda/wake_period.lua b/unit_tests/scripts/linda/wake_period.lua index e4a900d..d2dccc3 100644 --- a/unit_tests/scripts/linda/wake_period.lua +++ b/unit_tests/scripts/linda/wake_period.lua @@ -6,7 +6,7 @@ local lanes = require_lanes_result_1 local body = function(linda_) -- a blocking read that lasts longer than the tested wake_period values linda_:receive(2, "empty_slot") - return true + return "done" end -- if we don't cancel the lane, we should wait the whole duration @@ -22,7 +22,8 @@ local function check_wake_duration(linda_, expected_, do_cancel_) assert(result == false and reason == 'timeout', "unexpected cancel result") end -- this should wait until the linda wakes by itself before the actual receive timeout and sees the cancel request - h:join() + local r, ret = h:join() + assert(r == true and ret == "done") local t1 = lanes.now_secs() local delta = t1 - t0 -- the linda should check for cancellation at about the expected period, not earlier -- cgit v1.2.3-55-g6feb