diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/track_lanes.lua | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/track_lanes.lua b/tests/track_lanes.lua new file mode 100644 index 0000000..46cfdad --- /dev/null +++ b/tests/track_lanes.lua | |||
@@ -0,0 +1,72 @@ | |||
1 | local lanes = require "lanes" .configure{ with_timers = false, track_lanes = true} | ||
2 | |||
3 | local wait | ||
4 | do | ||
5 | local linda = lanes.linda() | ||
6 | wait = function( seconds_) | ||
7 | linda:receive( seconds_, "dummy_key") | ||
8 | end | ||
9 | end | ||
10 | |||
11 | print "hello" | ||
12 | |||
13 | local track = function( title_) | ||
14 | print( title_) | ||
15 | for k, v in pairs( lanes.threads()) | ||
16 | do | ||
17 | print( k, v.name, v.status) | ||
18 | end | ||
19 | print( "\n") | ||
20 | end | ||
21 | |||
22 | local sleeper = function( name_, seconds_) | ||
23 | -- print( "entering '" .. name_ .. "'") | ||
24 | local lanes = require "lanes" | ||
25 | -- no set_debug_threadname in main thread | ||
26 | if set_debug_threadname | ||
27 | then | ||
28 | -- print( "set_debug_threadname('" .. name_ .. "')") | ||
29 | set_debug_threadname( name_) | ||
30 | end | ||
31 | -- suspend the lane for the specified duration with a failed linda read | ||
32 | wait( seconds_) | ||
33 | -- print( "exiting '" .. name_ .. "'") | ||
34 | end | ||
35 | |||
36 | -- sleeper( "main", 1) | ||
37 | |||
38 | -- the generator | ||
39 | local g = lanes.gen( "*", sleeper) | ||
40 | |||
41 | -- start a forever-waiting lane (nil timeout) | ||
42 | g( "forever") | ||
43 | |||
44 | -- start a lane that will last 2 seconds | ||
45 | g( "two_seconds", 2) | ||
46 | |||
47 | -- give a bit of time to reach the linda waiting call | ||
48 | wait( 0.1) | ||
49 | |||
50 | -- list the known lanes | ||
51 | track( "============= START") | ||
52 | |||
53 | -- wait until "two_seconds has completed" | ||
54 | wait(2.1) | ||
55 | |||
56 | track( "============= two_seconds dead") | ||
57 | |||
58 | -- this will collect the completed lane (and remove it from the tracking queue) | ||
59 | -- collectgarbage() | ||
60 | |||
61 | -- track( "============= two_seconds dead (after collectgarbage)") | ||
62 | |||
63 | -- start another lane that will last 2 seconds, with the same name | ||
64 | g( "two_seconds", 2) | ||
65 | |||
66 | -- give a bit of time to reach the linda waiting call | ||
67 | wait( 0.1) | ||
68 | |||
69 | -- list the known lanes | ||
70 | track( "============= ANOTHER") | ||
71 | |||
72 | print "done" \ No newline at end of file | ||