aboutsummaryrefslogtreecommitdiff
path: root/unit_tests/scripts/lane
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2026-02-26 11:02:55 +0100
committerBenoit Germain <benoit.germain@ubisoft.com>2026-02-26 11:02:55 +0100
commit4f97720e4c3944ccf9b9742028dc697c2dd94c5a (patch)
tree259ec6c30971f3ca0c7e0f38898ab7f7aa548af9 /unit_tests/scripts/lane
parent6b8c83b3bc44b0a1bc186f58de0fea6dfc214c4b (diff)
downloadlanes-4f97720e4c3944ccf9b9742028dc697c2dd94c5a.tar.gz
lanes-4f97720e4c3944ccf9b9742028dc697c2dd94c5a.tar.bz2
lanes-4f97720e4c3944ccf9b9742028dc697c2dd94c5a.zip
change cancel_test() to raise cancel_error on hard-cancels by default
Diffstat (limited to 'unit_tests/scripts/lane')
-rw-r--r--unit_tests/scripts/lane/cooperative_shutdown.lua2
-rw-r--r--unit_tests/scripts/lane/tasking_cancelling.lua16
2 files changed, 13 insertions, 5 deletions
diff --git a/unit_tests/scripts/lane/cooperative_shutdown.lua b/unit_tests/scripts/lane/cooperative_shutdown.lua
index 0a0943e..3329e9d 100644
--- a/unit_tests/scripts/lane/cooperative_shutdown.lua
+++ b/unit_tests/scripts/lane/cooperative_shutdown.lua
@@ -7,7 +7,7 @@ local lane1 = function()
7 -- loop breaks on soft cancellation request 7 -- loop breaks on soft cancellation request
8 repeat 8 repeat
9 lanes.sleep(0) 9 lanes.sleep(0)
10 until cancel_test() 10 until cancel_test(true)
11 print "lane1 cancelled" 11 print "lane1 cancelled"
12end 12end
13 13
diff --git a/unit_tests/scripts/lane/tasking_cancelling.lua b/unit_tests/scripts/lane/tasking_cancelling.lua
index 395bee5..f7ad729 100644
--- a/unit_tests/scripts/lane/tasking_cancelling.lua
+++ b/unit_tests/scripts/lane/tasking_cancelling.lua
@@ -29,24 +29,32 @@ local 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)) 29assert(no_cancel_result == false, "cancel_test() should return boolean false, got " .. type(no_cancel_result) .. ": " .. tostring(no_cancel_result))
30 30
31-- cancellation of cooperating lanes 31-- cancellation of cooperating lanes
32local cooperative = function() 32-- query_only: if true, pass true to cancel_test() so that hard cancel returns "hard" instead of raising
33local cooperative = function(query_only_)
33 local fixture = assert(require "fixture") 34 local fixture = assert(require "fixture")
34 local which_cancel 35 local which_cancel
35 repeat 36 repeat
36 fixture.block_for(0.2) 37 fixture.block_for(0.2)
37 which_cancel = cancel_test() 38 which_cancel = cancel_test(query_only_)
38 until which_cancel 39 until which_cancel
39 return which_cancel 40 return which_cancel
40end 41end
41-- soft and hard are behaviorally equivalent when no blocking linda operation is involved 42-- for soft cancel, cancel_test() returns "soft" so the lane exits the loop and returns it
42local cooperative_lane_soft = lanes_gen("*", { name = 'auto' }, cooperative)() 43local cooperative_lane_soft = lanes_gen("*", { name = 'auto' }, cooperative)()
43local a, b = cooperative_lane_soft:cancel("soft", 0) -- issue request, do not wait for lane to terminate 44local a, b = cooperative_lane_soft:cancel("soft", 0) -- issue request, do not wait for lane to terminate
44assert(a == false and b == "timeout", "got " .. tostring(a) .. " " .. tostring(b)) 45assert(a == false and b == "timeout", "got " .. tostring(a) .. " " .. tostring(b))
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() 46assert(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()
47-- for hard cancel, cancel_test() raises cancel_error, so the lane ends up in the cancelled state
46local cooperative_lane_hard = lanes_gen("*", { name = 'auto' }, cooperative)() 48local cooperative_lane_hard = lanes_gen("*", { name = 'auto' }, cooperative)()
47local c, d = cooperative_lane_hard:cancel("hard", 0) -- issue request, do not wait for lane to terminate 49local c, d = cooperative_lane_hard:cancel("hard", 0) -- issue request, do not wait for lane to terminate
48assert(c == false and d == "timeout", "got " .. tostring(c) .. " " .. tostring(d)) 50assert(c == false and d == "timeout", "got " .. tostring(c) .. " " .. tostring(d))
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() 51assert(cooperative_lane_hard[1] == nil, "cancelled lane first result should be nil, got " .. type(cooperative_lane_hard[1]) .. ": " .. tostring(cooperative_lane_hard[1]))
52assert(cooperative_lane_hard[2] == lanes.cancel_error, "cancelled lane second result should be cancel_error")
53-- for hard cancel with query_only=true, cancel_test(true) returns "hard" so the lane exits the loop and returns it
54local cooperative_lane_hard_query = lanes_gen("*", { name = 'auto' }, cooperative)(true)
55local e, f = cooperative_lane_hard_query:cancel("hard", 0) -- issue request, do not wait for lane to terminate
56assert(e == false and f == "timeout", "got " .. tostring(e) .. " " .. tostring(f))
57assert(cooperative_lane_hard_query[1] == "hard", "cancel_test(true) should return \"hard\", got " .. type(cooperative_lane_hard_query[1]) .. ": " .. tostring(cooperative_lane_hard_query[1]))
50 58
51-- ################################################################################################## 59-- ##################################################################################################
52 60