diff options
Diffstat (limited to '')
-rw-r--r-- | unit_tests/scripts/lane/tasking_cancelling.lua | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/unit_tests/scripts/lane/tasking_cancelling.lua b/unit_tests/scripts/lane/tasking_cancelling.lua index 8bee3a6..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,8 +18,30 @@ 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("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) |
21 | assert.failsnot(function() limited:limit("key", 1) end) | 46 | assert.failsnot(function() limited:limit("key", 1) end) |
22 | -- [[################################################ | 47 | -- [[################################################ |
@@ -61,7 +86,7 @@ PRINT "wait_receive_lane is cancelled" | |||
61 | local wait_receive_batched = function() | 86 | local wait_receive_batched = function() |
62 | local k, v1, v2 | 87 | local k, v1, v2 |
63 | set_finalizer(function() print("wait_receive_batched", k, v1, v2) end) | 88 | set_finalizer(function() print("wait_receive_batched", k, v1, v2) end) |
64 | k, v1, v2 = limited:receive(limited.batched, "dummy", 2) -- infinite timeout, returns only when lane is cancelled | 89 | k, v1, v2 = limited:receive_batched("dummy", 2) -- infinite timeout, returns only when lane is cancelled |
65 | end | 90 | end |
66 | 91 | ||
67 | local wait_receive_batched_lane = lanes_gen("*", { name = 'auto' }, wait_receive_batched)() | 92 | local wait_receive_batched_lane = lanes_gen("*", { name = 'auto' }, wait_receive_batched)() |