diff options
Diffstat (limited to '')
-rw-r--r-- | unit_tests/scripts/lane/cooperative_shutdown.lua | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/unit_tests/scripts/lane/cooperative_shutdown.lua b/unit_tests/scripts/lane/cooperative_shutdown.lua index 1204e35..0a0943e 100644 --- a/unit_tests/scripts/lane/cooperative_shutdown.lua +++ b/unit_tests/scripts/lane/cooperative_shutdown.lua | |||
@@ -1,10 +1,10 @@ | |||
1 | local lanes = require "lanes" | 1 | local lanes = require "lanes".configure{on_state_create = require "fixture".on_state_create} |
2 | 2 | ||
3 | -- launch lanes that cooperate properly with cancellation request | 3 | -- launch lanes that cooperate properly with cancellation request |
4 | 4 | ||
5 | local lane1 = function() | 5 | local lane1 = function() |
6 | lane_threadname("lane1") | 6 | lane_threadname("lane1") |
7 | -- loop breaks on 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() |
@@ -23,7 +23,6 @@ end | |||
23 | local lane3 = function() | 23 | local lane3 = function() |
24 | lane_threadname("lane3") | 24 | lane_threadname("lane3") |
25 | -- this one cooperates too, because of the hook cancellation modes that Lanes will be using | 25 | -- this one cooperates too, because of the hook cancellation modes that Lanes will be using |
26 | -- but not with LuaJIT, because the function is compiled, and we don't call anyone, so no hook triggers | ||
27 | local fixture = require "fixture" | 26 | local fixture = require "fixture" |
28 | repeat until fixture.give_me_back(false) | 27 | repeat until fixture.give_me_back(false) |
29 | end | 28 | end |
@@ -31,9 +30,9 @@ end | |||
31 | 30 | ||
32 | 31 | ||
33 | -- the generators | 32 | -- the generators |
34 | local g1 = lanes.gen("*", lane1) | 33 | local g1 = lanes.gen("*", { name = 'auto' }, lane1) |
35 | local g2 = lanes.gen("*", lane2) | 34 | local g2 = lanes.gen("*", { name = 'auto' }, lane2) |
36 | local g3 = lanes.gen("*", lane3) | 35 | local g3 = lanes.gen("*", { name = 'auto' }, lane3) |
37 | 36 | ||
38 | -- launch lanes | 37 | -- launch lanes |
39 | local h1 = g1() | 38 | local h1 = g1() |
@@ -43,7 +42,14 @@ local h2 = g2(linda) | |||
43 | 42 | ||
44 | local h3 = g3() | 43 | local h3 = g3() |
45 | 44 | ||
46 | -- wait until they are both started | 45 | lanes.sleep(0.1) |
47 | repeat until h1.status == "running" and h2.status == "waiting" and h3.status == "running" | 46 | |
47 | local is_running = function(lane_h) | ||
48 | local status = lane_h.status | ||
49 | return status == "running" or status == "waiting" | ||
50 | end | ||
51 | |||
52 | -- wait until they are all started | ||
53 | repeat until is_running(h1) and is_running(h2) and is_running(h3) | ||
48 | 54 | ||
49 | -- let the script terminate, Lanes should not crash at shutdown | 55 | -- let the script terminate, Lanes should not crash at shutdown |