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 --- tests/appendud.lua | 2 +- tests/basic.lua | 17 +++++++++-------- tests/error.lua | 7 +++---- tests/finalizer.lua | 4 ++-- tests/func_is_string.lua | 13 +++++++------ tests/launchtest.lua | 4 ++-- tests/linda_perf.lua | 7 ++++--- tests/perftest.lua | 4 ++-- tests/pingpong.lua | 8 +++++--- tests/rupval.lua | 6 +++--- tests/tobeclosed.lua | 5 +++-- 11 files changed, 41 insertions(+), 36 deletions(-) (limited to 'tests') diff --git a/tests/appendud.lua b/tests/appendud.lua index f6f99c1..2a8c8ce 100644 --- a/tests/appendud.lua +++ b/tests/appendud.lua @@ -49,7 +49,7 @@ assert(not err) -- test -- print("t:join()") a,b,c = t[1],t[2],t[3] -- Need to explicitly wait for the thread, since 'ipairs()' does not ---a,b,c = t:join() -- Need to explicitly wait for the thread, since 'ipairs()' does not +--r,a,b,c = t:join() -- Need to explicitly wait for the thread, since 'ipairs()' does not -- value the '__index' metamethod (wouldn't it be cool if it did..?) print(a,b,c) diff --git a/tests/basic.lua b/tests/basic.lua index 9aaad97..f393175 100644 --- a/tests/basic.lua +++ b/tests/basic.lua @@ -507,19 +507,20 @@ 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 +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) - assert(a==14) - assert(b==13) - assert(c==12) - assert(d==nil) + print(h:get_threadname(), r,a,b,c,d) + assert(r == true) + assert(a == 14) + assert(b == 13) + assert(c == 12) + assert(d == nil) end local nameof_type, nameof_name = lanes.nameof(print) diff --git a/tests/error.lua b/tests/error.lua index 28cfff1..76ceea4 100644 --- a/tests/error.lua +++ b/tests/error.lua @@ -173,8 +173,7 @@ local do_error_catching_test = function(error_reporting_mode_, error_value_, fin local h = start_lane(error_reporting_mode_, error_value_, finalizer_, finalizer_error_value_) local ret,err,stack= h:join() -- wait for the lane (no automatic error propagation) WR("Processing results for {", error_reporting_mode_, error_value_, finalizer_, finalizer_error_value_, "}") - if err then - assert(ret == nil) + if ret == nil then assert(error_reporting_mode_ == "minimal" or type(stack)=="table") -- only true if lane was configured with error_trace_level ~= "minimal" if err == error_value_ then WR("Lane regular error: ", err) @@ -198,8 +197,8 @@ local do_error_catching_test = function(error_reporting_mode_, error_value_, fin end end else -- no error - assert(ret == "success") - WR("No error in lane: ", ret) + assert(ret == true and err == "success") + WR("No error in lane: ", err, ret) end WR "TEST OK" end diff --git a/tests/finalizer.lua b/tests/finalizer.lua index ac5ce8b..9fa12dc 100644 --- a/tests/finalizer.lua +++ b/tests/finalizer.lua @@ -77,8 +77,8 @@ local do_test = function(error_) local h = lgen(error_) - local _,err,stack = h:join() -- wait for the lane (no automatic error propagation) - if err then + local r,err,stack = h:join() -- wait for the lane (no automatic error propagation) + if not r then assert(stack, "no stack trace on error, check 'error_trace_level'") io.stderr:write( "Lane error: "..tostring(err).."\n" ) io.stderr:write( "\t", table.concat(stack,"\t\n"), "\n" ) diff --git a/tests/func_is_string.lua b/tests/func_is_string.lua index 5de4c60..3c91603 100644 --- a/tests/func_is_string.lua +++ b/tests/func_is_string.lua @@ -21,16 +21,17 @@ end local options = {globals = { b = 666 }} -local gen1 = lanes.gen("*", { name = 'auto' }, "return true, dofile('fibonacci.lua')") -local gen2 = lanes.gen(options, { name = 'auto' }, "return b") +local gen1 = lanes.gen("*", { name = 'auto' }, "return true, error('bob')") fibLane = gen1() lanes.sleep(0.1) print(fibLane, fibLane.status) -local _status, _err = fibLane:join() -print(_status, _err) +local _r, _err, _stk = fibLane:join() +assert(_r == nil, "got " .. tostring(_r) .. " " .. tostring(_err) .. " " .. tostring(_stk)) -retLane1, retLane2 = gen2(), gen2() +local gen2 = lanes.gen(options, { name = 'auto' }, "return b") +local retLane1, retLane2 = gen2(), gen2() print( retLane1[1], retLane2[1]) -print "TEST OK" \ No newline at end of file +assert(retLane1[1] == 666 and retLane2[1] == 666) +print "TEST OK" diff --git a/tests/launchtest.lua b/tests/launchtest.lua index 57411e1..cdd6ffc 100644 --- a/tests/launchtest.lua +++ b/tests/launchtest.lua @@ -69,8 +69,8 @@ else io.stderr:write( N.." lanes launched.\n" ) for i=1,N do - local rc= t[i]:join() - assert( rc==i ) + local r,rc = t[i]:join() + assert( r == true and rc == i ) end io.stderr:write( N.." lanes finished.\n" ) diff --git a/tests/linda_perf.lua b/tests/linda_perf.lua index 83b8921..e68d552 100644 --- a/tests/linda_perf.lua +++ b/tests/linda_perf.lua @@ -56,7 +56,7 @@ local eater = function( l, loop) -- print "loop is over" key, val = l:receive( "done") print("eater: done ("..val..")") - return true + return "ate everything" end -- ################################################################################################# @@ -74,7 +74,7 @@ local gobbler = function( l, loop, batch) print "loop is over" key, val = l:receive( "done") print("gobbler: done ("..val..")") - return true + return "gobbled everything" end -- ################################################################################################# @@ -123,7 +123,8 @@ local function ziva1( preloop, loop, batch) end end l:send( "done" ,"are you happy?") - lane:join() + local r, ret = lane:join() + assert(r == true and type(ret) == "string", "got " .. tostring(r) .. " " .. tostring(ret)) return lanes.now_secs() - t1 end diff --git a/tests/perftest.lua b/tests/perftest.lua index fe43cca..35e164d 100644 --- a/tests/perftest.lua +++ b/tests/perftest.lua @@ -175,9 +175,9 @@ else -- Make sure all lanes finished -- for i=1,N do - local tmp= t[i]:join() + local r, tmp = t[i]:join() -- this assert will trigger if you change M to values below 1000 in order to solve C stack overflow - assert( type(tmp)=="table" and tmp[1]==2 and tmp[168]==997 ) + assert( r == true and type(tmp) == "table" and tmp[1] == 2 and tmp[168] == 997 ) end end diff --git a/tests/pingpong.lua b/tests/pingpong.lua index 06c0903..1ed5b9a 100644 --- a/tests/pingpong.lua +++ b/tests/pingpong.lua @@ -21,13 +21,15 @@ local pingpong = function(name, qr, qs, start) q:send(qs, val) count = count + 1 end - return true + return "ping!" end -- pingpong("L1", '0', '1', true) local t1, err1 = lanes.gen("*", { name = 'auto' }, pingpong)("L1", 'a', 'b', true) local t2, err2 = lanes.gen("*", { name = 'auto' }, pingpong)("L2", 'b', 'a', false) -t1:join() -t2:join() +local r1, ret1 = t1:join() +assert(r1 == true and ret1 == "ping!") +local r2, ret2 = t2:join() +assert(r2 == true and ret2 == "ping!") print "TEST OK" diff --git a/tests/rupval.lua b/tests/rupval.lua index ad5ad9d..c6743b3 100644 --- a/tests/rupval.lua +++ b/tests/rupval.lua @@ -26,17 +26,17 @@ end local g = lanes.gen( "base", { name = 'auto' }, a) local l = g(7) -local r = l:join() +local _, r = l:join() assert(r == y) print(r) local l = g(8) -local r = l:join() +local _, r = l:join() assert(r == z) print(r) local l = g(9) -local r = l:join() +local _, r = l:join() assert(r == x) print(r) diff --git a/tests/tobeclosed.lua b/tests/tobeclosed.lua index 447b936..fd157e2 100644 --- a/tests/tobeclosed.lua +++ b/tests/tobeclosed.lua @@ -106,7 +106,7 @@ do local _count, l_out = l:get("trip") -- linda from arguments local l_arg = l_arg_ - return true + return "done" end local close_handler_f = function(linda_, err_) @@ -118,7 +118,8 @@ do l:set("trip", l_in) do - lanes.gen("*", { name = 'auto' }, lane_body)(l_in):join() + local r, ret = lanes.gen("*", { name = 'auto' }, lane_body)(l_in):join() + assert(r == true and ret == "done") end local _count, _closed = l_in:get("closed") assert(_count == 1 and _closed == 2) -- cgit v1.2.3-55-g6feb