aboutsummaryrefslogtreecommitdiff
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
parent469bc8451db8078dca6cac4350cf874c47cef5f2 (diff)
downloadlanes-6b8c83b3bc44b0a1bc186f58de0fea6dfc214c4b.tar.gz
lanes-6b8c83b3bc44b0a1bc186f58de0fea6dfc214c4b.tar.bz2
lanes-6b8c83b3bc44b0a1bc186f58de0fea6dfc214c4b.zip
Improve cancel_test() documentation and unit test
-rw-r--r--docs/index.html8
-rw-r--r--unit_tests/scripts/lane/tasking_cancelling.lua16
2 files changed, 19 insertions, 5 deletions
diff --git a/docs/index.html b/docs/index.html
index 452dcfa..3dc2b61 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -1294,10 +1294,14 @@
1294 This means the execution of the lane will resume although the operation has not completed, to give the lane a chance to detect cancellation (even in the case the code waits on a <a href="#lindas">linda</a> with infinite timeout). 1294 This means the execution of the lane will resume although the operation has not completed, to give the lane a chance to detect cancellation (even in the case the code waits on a <a href="#lindas">linda</a> with infinite timeout).
1295 <br /> 1295 <br />
1296 The code should be able to handle this situation appropriately if required (in other words, it should gracefully handle the fact that it didn't receive the expected values). 1296 The code should be able to handle this situation appropriately if required (in other words, it should gracefully handle the fact that it didn't receive the expected values).
1297 <br />
1298 It is also possible to manually test for cancel requests with <tt>cancel_test()</tt>.
1299</p> 1297</p>
1300 1298
1299 <table border="1" bgcolor="#E0E0FF" cellpadding="10" style="width:50%"><tr><td><pre>
1300 false|"soft"|"hard" = cancel_test() -- inside the lane
1301</pre></td></tr></table>
1302<p>
1303 Lanes installs the function <tt>cancel_test()</tt> in each created lane to manually test for cancel requests.
1304</p>
1301 1305
1302<!-- finalizers +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 1306<!-- finalizers +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
1303<hr/> 1307<hr/>
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