aboutsummaryrefslogtreecommitdiff
path: root/unit_tests/scripts
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2026-02-26 10:17:36 +0100
committerBenoit Germain <benoit.germain@ubisoft.com>2026-02-26 10:17:36 +0100
commit6b8c83b3bc44b0a1bc186f58de0fea6dfc214c4b (patch)
treecedc4e5c7ded4393e20acdb932d82ffa1b8961f0 /unit_tests/scripts
parent469bc8451db8078dca6cac4350cf874c47cef5f2 (diff)
downloadlanes-6b8c83b3bc44b0a1bc186f58de0fea6dfc214c4b.tar.gz
lanes-6b8c83b3bc44b0a1bc186f58de0fea6dfc214c4b.tar.bz2
lanes-6b8c83b3bc44b0a1bc186f58de0fea6dfc214c4b.zip
Improve cancel_test() documentation and unit test
Diffstat (limited to 'unit_tests/scripts')
-rw-r--r--unit_tests/scripts/lane/tasking_cancelling.lua16
1 files changed, 13 insertions, 3 deletions
diff --git a/unit_tests/scripts/lane/tasking_cancelling.lua b/unit_tests/scripts/lane/tasking_cancelling.lua
index d153ffa..395bee5 100644
--- a/unit_tests/scripts/lane/tasking_cancelling.lua
+++ b/unit_tests/scripts/lane/tasking_cancelling.lua
@@ -18,6 +18,16 @@ local lanes_linda = assert(lanes.linda)
18-- ################################################################################################## 18-- ##################################################################################################
19-- ################################################################################################## 19-- ##################################################################################################
20 20
21-- test that cancel_test() returns exactly false (boolean) when no cancel is pending
22local no_cancel = function()
23 local result = cancel_test()
24 assert(result == false, "cancel_test() should return boolean false when not cancelled, got " .. type(result) .. ": " .. tostring(result))
25 return result
26end
27local no_cancel_lane = lanes_gen("*", { name = 'auto' }, no_cancel)()
28local no_cancel_result = no_cancel_lane[1]
29assert(no_cancel_result == false, "cancel_test() should return boolean false, got " .. type(no_cancel_result) .. ": " .. tostring(no_cancel_result))
30
21-- cancellation of cooperating lanes 31-- cancellation of cooperating lanes
22local cooperative = function() 32local cooperative = function()
23 local fixture = assert(require "fixture") 33 local fixture = assert(require "fixture")
@@ -32,11 +42,11 @@ end
32local cooperative_lane_soft = lanes_gen("*", { name = 'auto' }, cooperative)() 42local cooperative_lane_soft = lanes_gen("*", { name = 'auto' }, cooperative)()
33local a, b = cooperative_lane_soft:cancel("soft", 0) -- issue request, do not wait for lane to terminate 43local a, b = cooperative_lane_soft:cancel("soft", 0) -- issue request, do not wait for lane to terminate
34assert(a == false and b == "timeout", "got " .. tostring(a) .. " " .. tostring(b)) 44assert(a == false and b == "timeout", "got " .. tostring(a) .. " " .. tostring(b))
35assert(cooperative_lane_soft[1] == "soft") -- return value of the lane body is the value returned by cancel_test() 45assert(cooperative_lane_soft[1] == "soft", "cancel_test() should return \"soft\", got " .. type(cooperative_lane_soft[1]) .. ": " .. tostring(cooperative_lane_soft[1])) -- return value of the lane body is the value returned by cancel_test()
36local cooperative_lane_hard = lanes_gen("*", { name = 'auto' }, cooperative)() 46local cooperative_lane_hard = lanes_gen("*", { name = 'auto' }, cooperative)()
37local c, d = cooperative_lane_hard:cancel("hard", 0) -- issue request, do not wait for lane to terminate 47local c, d = cooperative_lane_hard:cancel("hard", 0) -- issue request, do not wait for lane to terminate
38assert(a == false and b == "timeout", "got " .. tostring(c) .. " " .. tostring(d)) 48assert(c == false and d == "timeout", "got " .. tostring(c) .. " " .. tostring(d))
39assert(cooperative_lane_hard[1] == "hard") -- return value of the lane body is the value returned by cancel_test() 49assert(cooperative_lane_hard[1] == "hard", "cancel_test() should return \"hard\", got " .. type(cooperative_lane_hard[1]) .. ": " .. tostring(cooperative_lane_hard[1])) -- return value of the lane body is the value returned by cancel_test()
40 50
41-- ################################################################################################## 51-- ##################################################################################################
42 52