diff options
| author | Benoit Germain <benoit.germain@ubisoft.com> | 2026-02-26 10:17:36 +0100 |
|---|---|---|
| committer | Benoit Germain <benoit.germain@ubisoft.com> | 2026-02-26 10:17:36 +0100 |
| commit | 6b8c83b3bc44b0a1bc186f58de0fea6dfc214c4b (patch) | |
| tree | cedc4e5c7ded4393e20acdb932d82ffa1b8961f0 /unit_tests/scripts | |
| parent | 469bc8451db8078dca6cac4350cf874c47cef5f2 (diff) | |
| download | lanes-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.lua | 16 |
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 | ||
| 22 | local 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 | ||
| 26 | end | ||
| 27 | local no_cancel_lane = lanes_gen("*", { name = 'auto' }, no_cancel)() | ||
| 28 | local no_cancel_result = no_cancel_lane[1] | ||
| 29 | assert(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 |
| 22 | local cooperative = function() | 32 | local cooperative = function() |
| 23 | local fixture = assert(require "fixture") | 33 | local fixture = assert(require "fixture") |
| @@ -32,11 +42,11 @@ end | |||
| 32 | local cooperative_lane_soft = lanes_gen("*", { name = 'auto' }, cooperative)() | 42 | local cooperative_lane_soft = lanes_gen("*", { name = 'auto' }, cooperative)() |
| 33 | local a, b = cooperative_lane_soft:cancel("soft", 0) -- issue request, do not wait for lane to terminate | 43 | local a, b = cooperative_lane_soft:cancel("soft", 0) -- issue request, do not wait for lane to terminate |
| 34 | assert(a == false and b == "timeout", "got " .. tostring(a) .. " " .. tostring(b)) | 44 | assert(a == false and b == "timeout", "got " .. tostring(a) .. " " .. tostring(b)) |
| 35 | assert(cooperative_lane_soft[1] == "soft") -- return value of the lane body is the value returned by cancel_test() | 45 | assert(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() |
| 36 | local cooperative_lane_hard = lanes_gen("*", { name = 'auto' }, cooperative)() | 46 | local cooperative_lane_hard = lanes_gen("*", { name = 'auto' }, cooperative)() |
| 37 | local c, d = cooperative_lane_hard:cancel("hard", 0) -- issue request, do not wait for lane to terminate | 47 | local c, d = cooperative_lane_hard:cancel("hard", 0) -- issue request, do not wait for lane to terminate |
| 38 | assert(a == false and b == "timeout", "got " .. tostring(c) .. " " .. tostring(d)) | 48 | assert(c == false and d == "timeout", "got " .. tostring(c) .. " " .. tostring(d)) |
| 39 | assert(cooperative_lane_hard[1] == "hard") -- return value of the lane body is the value returned by cancel_test() | 49 | assert(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 | ||
