aboutsummaryrefslogtreecommitdiff
path: root/unit_tests/scripts
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2025-06-05 16:03:22 +0200
committerBenoit Germain <benoit.germain@ubisoft.com>2025-06-05 16:03:22 +0200
commitbfdc7a92c4e3e99522abb6d90ef2cbb021f36fc8 (patch)
tree00f6633878b21dda6cad1177d5619a501b4ac0a4 /unit_tests/scripts
parentf73702bcf4372a149b8b01a512c0e086b1e679e2 (diff)
downloadlanes-bfdc7a92c4e3e99522abb6d90ef2cbb021f36fc8.tar.gz
lanes-bfdc7a92c4e3e99522abb6d90ef2cbb021f36fc8.tar.bz2
lanes-bfdc7a92c4e3e99522abb6d90ef2cbb021f36fc8.zip
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
Diffstat (limited to 'unit_tests/scripts')
-rw-r--r--unit_tests/scripts/coro/basics.lua6
-rw-r--r--unit_tests/scripts/lane/tasking_join_test.lua16
-rw-r--r--unit_tests/scripts/linda/wake_period.lua5
3 files changed, 18 insertions, 9 deletions
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
85 assert(h3:resume(1) == nil) 85 assert(h3:resume(1) == nil)
86 86
87 -- similarly, we can get them with join() 87 -- similarly, we can get them with join()
88 assert(h3:join() == "world" and h3.status == "suspended") 88 local r3, ret3 = h3:join()
89 assert(r3 == true and ret3 == "world" and h3.status == "suspended")
89 -- since we consumed the returned values, they should not be here when we resume 90 -- since we consumed the returned values, they should not be here when we resume
90 assert(h3:resume(2) == nil) 91 assert(h3:resume(2) == nil)
91 92
@@ -93,5 +94,6 @@ if true then
93 assert(h3:resume(3) == "!") 94 assert(h3:resume(3) == "!")
94 95
95 -- the final return value of the lane body remains to be read 96 -- the final return value of the lane body remains to be read
96 assert(h3:join() == "done!" and h3.status == "done") 97 local r3, ret3 = h3:join()
98 assert(r3 == true and ret3 == "done!" and h3.status == "done")
97end 99end
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
30 30
31PRINT("---=== :join test ===---", "\n\n") 31PRINT("---=== :join test ===---", "\n\n")
32 32
33-- a lane body that returns nothing is successfully joined with true, nil
34local r, ret = lanes_gen(function() end)():join()
35assert(r == true and ret == nil)
36
33-- NOTE: 'unpack()' cannot be used on the lane handle; it will always return nil 37-- NOTE: 'unpack()' cannot be used on the lane handle; it will always return nil
34-- (unless [1..n] has been read earlier, in which case it would seemingly 38-- (unless [1..n] has been read earlier, in which case it would seemingly
35-- work). 39-- work).
36 40
37local S= lanes_gen("table", { name = 'auto', gc_cb = gc_cb }, 41local S = lanes_gen("table", { name = 'auto', gc_cb = gc_cb },
38 function(arg) 42 function(arg)
39 lane_threadname "join test lane" 43 lane_threadname "join test lane"
40 set_finalizer(function() end) 44 set_finalizer(function() end)
45 -- take arg table, reverse its contents in aux, then return the unpacked result
41 local aux= {} 46 local aux= {}
42 for i, v in ipairs(arg) do 47 for i, v in ipairs(arg) do
43 table.insert(aux, 1, v) 48 table.insert(aux, 1, v)
@@ -46,15 +51,16 @@ local S= lanes_gen("table", { name = 'auto', gc_cb = gc_cb },
46 return (unpack or table.unpack)(aux) 51 return (unpack or table.unpack)(aux)
47end) 52end)
48 53
49h= S { 12, 13, 14 } -- execution starts, h[1..3] will get the return values 54local h = S { 12, 13, 14 } -- execution starts, h[1..3] will get the return values
50-- wait a bit so that the lane has a chance to set its debug name 55-- wait a bit so that the lane has a chance to set its debug name
51SLEEP(0.5) 56SLEEP(0.5)
52print("joining with '" .. h:get_threadname() .. "'") 57print("joining with '" .. h:get_threadname() .. "'")
53local a,b,c,d= h:join() 58local r, a, b, c, d = h:join()
54if h.status == "error" then 59if h.status == "error" then
55 print(h:get_threadname(), "error: " , a, b, c, d) 60 print(h:get_threadname(), "error: " , r, a, b, c, d)
56else 61else
57 print(h:get_threadname(), a,b,c,d) 62 print(h:get_threadname(), r, a, b, c, d)
63 assert(r==true, "r == " .. tostring(r))
58 assert(a==14, "a == " .. tostring(a)) 64 assert(a==14, "a == " .. tostring(a))
59 assert(b==13, "b == " .. tostring(b)) 65 assert(b==13, "b == " .. tostring(b))
60 assert(c==12, "c == " .. tostring(c)) 66 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
6local body = function(linda_) 6local body = function(linda_)
7 -- a blocking read that lasts longer than the tested wake_period values 7 -- a blocking read that lasts longer than the tested wake_period values
8 linda_:receive(2, "empty_slot") 8 linda_:receive(2, "empty_slot")
9 return true 9 return "done"
10end 10end
11 11
12-- if we don't cancel the lane, we should wait the whole duration 12-- 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_)
22 assert(result == false and reason == 'timeout', "unexpected cancel result") 22 assert(result == false and reason == 'timeout', "unexpected cancel result")
23 end 23 end
24 -- this should wait until the linda wakes by itself before the actual receive timeout and sees the cancel request 24 -- this should wait until the linda wakes by itself before the actual receive timeout and sees the cancel request
25 h:join() 25 local r, ret = h:join()
26 assert(r == true and ret == "done")
26 local t1 = lanes.now_secs() 27 local t1 = lanes.now_secs()
27 local delta = t1 - t0 28 local delta = t1 - t0
28 -- the linda should check for cancellation at about the expected period, not earlier 29 -- the linda should check for cancellation at about the expected period, not earlier