diff options
Diffstat (limited to 'unit_tests/scripts/lane/tasking_cancelling.lua')
-rw-r--r-- | unit_tests/scripts/lane/tasking_cancelling.lua | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/unit_tests/scripts/lane/tasking_cancelling.lua b/unit_tests/scripts/lane/tasking_cancelling.lua index 873140e..d153ffa 100644 --- a/unit_tests/scripts/lane/tasking_cancelling.lua +++ b/unit_tests/scripts/lane/tasking_cancelling.lua | |||
@@ -1,4 +1,7 @@ | |||
1 | local require_lanes_result_1, require_lanes_result_2 = require "lanes".configure(config).configure() | 1 | local require_fixture_result_1, require_fixture_result_2 = require "fixture" |
2 | local fixture = assert(require_fixture_result_1) | ||
3 | |||
4 | local require_lanes_result_1, require_lanes_result_2 = require "lanes".configure{on_state_create = fixture.on_state_create}.configure() | ||
2 | print("require_lanes_result:", require_lanes_result_1, require_lanes_result_2) | 5 | print("require_lanes_result:", require_lanes_result_1, require_lanes_result_2) |
3 | local lanes = require_lanes_result_1 | 6 | local lanes = require_lanes_result_1 |
4 | 7 | ||
@@ -15,6 +18,28 @@ local lanes_linda = assert(lanes.linda) | |||
15 | -- ################################################################################################## | 18 | -- ################################################################################################## |
16 | -- ################################################################################################## | 19 | -- ################################################################################################## |
17 | 20 | ||
21 | -- cancellation of cooperating lanes | ||
22 | local cooperative = function() | ||
23 | local fixture = assert(require "fixture") | ||
24 | local which_cancel | ||
25 | repeat | ||
26 | fixture.block_for(0.2) | ||
27 | which_cancel = cancel_test() | ||
28 | until which_cancel | ||
29 | return which_cancel | ||
30 | end | ||
31 | -- soft and hard are behaviorally equivalent when no blocking linda operation is involved | ||
32 | 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 | ||
34 | 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() | ||
36 | 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 | ||
38 | assert(a == false and b == "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() | ||
40 | |||
41 | -- ################################################################################################## | ||
42 | |||
18 | -- cancellation of lanes waiting on a linda | 43 | -- cancellation of lanes waiting on a linda |
19 | local limited = lanes_linda{name = "limited"} | 44 | local limited = lanes_linda{name = "limited"} |
20 | assert.fails(function() limited:limit("key", -1) end) | 45 | assert.fails(function() limited:limit("key", -1) end) |