aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Germain <bnt.germain@gmail.com>2012-09-26 21:22:30 +0200
committerBenoit Germain <bnt.germain@gmail.com>2012-09-26 21:22:30 +0200
commitbba4ecea15320dfbf8edf35f7361de374d895ace (patch)
tree73bd0bfd29d2c4dbfe3a46681b0e3b2261352207 /tests
parent282f59ca02d1d1f304b9126b84a8b1427caf3172 (diff)
downloadlanes-bba4ecea15320dfbf8edf35f7361de374d895ace.tar.gz
lanes-bba4ecea15320dfbf8edf35f7361de374d895ace.tar.bz2
lanes-bba4ecea15320dfbf8edf35f7361de374d895ace.zip
version 3.4.0
* new method linda:dump() that outputs the full contents of a linda as a table, also linked to __towatch for Decoda support * linda:receive() API change! * instead of [val, key], linda:receive( timeout, key) returns [key, val] * instead of [val, [...]], linda:receive( timeout, linda.batched key) returns [key, val[, ...]] this is to unify the return values of regular and batched mode, and to be able to tell when batched mode is interrupted by a lane cancellation * fixed Lua 5.2 build to take into account the "loaders"->"searchers" name change in 'package' module. * a bit of html cleanup and added some infos in the documentation regarding the Lanes internals
Diffstat (limited to 'tests')
-rw-r--r--tests/basic.lua68
-rw-r--r--tests/ehynes.lua2
-rw-r--r--tests/errhangtest.lua2
-rw-r--r--tests/fifo.lua2
-rw-r--r--tests/linda_perf.lua8
-rw-r--r--tests/nameof.lua4
-rw-r--r--tests/objects.lua2
-rw-r--r--tests/parallel_os_calls.lua14
-rw-r--r--tests/timer.lua4
9 files changed, 84 insertions, 22 deletions
diff --git a/tests/basic.lua b/tests/basic.lua
index eb8c04b..3eee59e 100644
--- a/tests/basic.lua
+++ b/tests/basic.lua
@@ -136,6 +136,50 @@ end
136PRINT(" "..st) 136PRINT(" "..st)
137assert( st == "cancelled" ) 137assert( st == "cancelled" )
138 138
139-- cancellation of lanes waiting on a linda
140local limited = lanes.linda()
141limited:limit( "key", 1)
142-- [[################################################
143limited:send( "key", "hello") -- saturate linda
144local wait_send = function()
145 local a,b
146 set_finalizer( function() print( "wait_send", a, b) end)
147 a,b = limited:send( "key", "bybye") -- infinite timeout, returns only when lane is cancelled
148end
149
150local wait_send_lane = lanes.gen( "*", wait_send)()
151repeat until wait_send_lane.status == "waiting"
152print "wait_send_lane is waiting"
153wait_send_lane:cancel()
154repeat until wait_send_lane.status == "cancelled"
155print "wait_send_lane is cancelled"
156--################################################]]
157local wait_receive = function()
158 local k, v
159 set_finalizer( function() print( "wait_receive", k, v) end)
160 k, v = limited:receive( "dummy") -- infinite timeout, returns only when lane is cancelled
161end
162
163local wait_receive_lane = lanes.gen( "*", wait_receive)()
164repeat until wait_receive_lane.status == "waiting"
165print "wait_receive_lane is waiting"
166wait_receive_lane:cancel()
167repeat until wait_receive_lane.status == "cancelled"
168print "wait_receive_lane is cancelled"
169--################################################]]
170local wait_receive_batched = function()
171 local k, v1, v2
172 set_finalizer( function() print( "wait_receive_batched", k, v1, v2) end)
173 k, v1, v2 = limited:receive( limited.batched, "dummy", 2) -- infinite timeout, returns only when lane is cancelled
174end
175
176local wait_receive_batched_lane = lanes.gen( "*", wait_receive_batched)()
177repeat until wait_receive_batched_lane.status == "waiting"
178print "wait_receive_batched_lane is waiting"
179wait_receive_batched_lane:cancel()
180repeat until wait_receive_batched_lane.status == "cancelled"
181print "wait_receive_batched_lane is cancelled"
182--################################################]]
139 183
140PRINT( "---=== Communications ===---") 184PRINT( "---=== Communications ===---")
141 185
@@ -148,16 +192,16 @@ local chunk= function( linda )
148 192
149 WR( "Lane starts!\n" ) 193 WR( "Lane starts!\n" )
150 194
151 local v 195 local k,v
152 v=receive(); WR( v.." received\n" ); assert( v==1 ) 196 k,v=receive(); WR( v.." received\n" ); assert( v==1 )
153 v=receive(); WR( v.." received\n" ); assert( v==2 ) 197 k,v=receive(); WR( v.." received\n" ); assert( v==2 )
154 v=receive(); WR( v.." received\n" ); assert( v==3 ) 198 k,v=receive(); WR( v.." received\n" ); assert( v==3 )
155 199
156 send( 1,2,3 ); WR( "1,2,3 sent\n" ) 200 send( 1,2,3 ); WR( "1,2,3 sent\n" )
157 send 'a'; WR( "'a' sent\n" ) 201 send 'a'; WR( "'a' sent\n" )
158 send { 'a', 'b', 'c', d=10 }; WR( "{'a','b','c',d=10} sent\n" ) 202 send { 'a', 'b', 'c', d=10 }; WR( "{'a','b','c',d=10} sent\n" )
159 203
160 v=receive(); WR( v.." received\n" ); assert( v==4 ) 204 k,v=receive(); WR( v.." received\n" ); assert( v==4 )
161 205
162 WR( "Lane ends!\n" ) 206 WR( "Lane ends!\n" )
163end 207end
@@ -170,7 +214,7 @@ assert( type(linda) == "userdata" )
170 214
171local function PEEK() return linda:get("<-") end 215local function PEEK() return linda:get("<-") end
172local function SEND(...) linda:send( "->", ... ) end 216local function SEND(...) linda:send( "->", ... ) end
173local function RECEIVE() return linda:receive( "<-" ) end 217local function RECEIVE() local k,v = linda:receive( "<-" ) return v end
174 218
175local t= lanes_gen("io",chunk)(linda) -- prepare & launch 219local t= lanes_gen("io",chunk)(linda) -- prepare & launch
176 220
@@ -226,7 +270,7 @@ local tc= lanes_gen( "io",
226 local function STAGE(str) 270 local function STAGE(str)
227 io.stderr:write( ch_in..": "..str.."\n" ) 271 io.stderr:write( ch_in..": "..str.."\n" )
228 linda:send( nil, ch_out, str ) 272 linda:send( nil, ch_out, str )
229 local v= linda:receive( nil, ch_in ) 273 local k,v= linda:receive( nil, ch_in )
230 assert(v==str) 274 assert(v==str)
231 end 275 end
232 STAGE("Hello") 276 STAGE("Hello")
@@ -264,13 +308,13 @@ local function chunk2( linda )
264 assert( info.linedefined > 200 ) -- start of 'chunk2' 308 assert( info.linedefined > 200 ) -- start of 'chunk2'
265 assert( info.currentline > info.linedefined ) -- line of 'debug.getinfo' 309 assert( info.currentline > info.linedefined ) -- line of 'debug.getinfo'
266 assert( info.lastlinedefined > info.currentline ) -- end of 'chunk2' 310 assert( info.lastlinedefined > info.currentline ) -- end of 'chunk2'
267 local func,k= linda:receive( "down" ) 311 local k,func= linda:receive( "down" )
268 assert( type(func)=="function" ) 312 assert( type(func)=="function" )
269 assert( k=="down" ) 313 assert( k=="down" )
270 314
271 func(linda) 315 func(linda)
272 316
273 local str= linda:receive( "down" ) 317 local k,str= linda:receive( "down" )
274 assert( str=="ok" ) 318 assert( str=="ok" )
275 319
276 linda:send( "up", function() return ":)" end, "ok2" ) 320 linda:send( "up", function() return ":)" end, "ok2" )
@@ -282,19 +326,19 @@ linda:send( "down", function(linda) linda:send( "up", "ready!" ) end,
282 "ok" ) 326 "ok" )
283-- wait to see if the tiny function gets executed 327-- wait to see if the tiny function gets executed
284-- 328--
285local s= linda:receive( "up" ) 329local k,s= linda:receive( "up" )
286PRINT(s) 330PRINT(s)
287assert( s=="ready!" ) 331assert( s=="ready!" )
288 332
289-- returns of the 'chunk2' itself 333-- returns of the 'chunk2' itself
290-- 334--
291local f= linda:receive( "up" ) 335local k,f= linda:receive( "up" )
292assert( type(f)=="function" ) 336assert( type(f)=="function" )
293 337
294local s2= f() 338local s2= f()
295assert( s2==":)" ) 339assert( s2==":)" )
296 340
297local ok2= linda:receive( "up" ) 341local k,ok2= linda:receive( "up" )
298assert( ok2 == "ok2" ) 342assert( ok2 == "ok2" )
299 343
300 344
diff --git a/tests/ehynes.lua b/tests/ehynes.lua
index fff008c..7609ddd 100644
--- a/tests/ehynes.lua
+++ b/tests/ehynes.lua
@@ -17,7 +17,7 @@ local receiver_gen = lanes.gen( 'base', 'os', 'string', 'io',
17 PRINT_FMT( 'receiver for message %s entered', message_name ) 17 PRINT_FMT( 'receiver for message %s entered', message_name )
18 local n = 1 18 local n = 1
19 while linda:receive(message_name) do 19 while linda:receive(message_name) do
20 PRINT_FMT( '%s %d receieved', message_name, n ) 20 PRINT_FMT( '%s %d received', message_name, n )
21 n = n + 1 21 n = n + 1
22 end 22 end
23 end 23 end
diff --git a/tests/errhangtest.lua b/tests/errhangtest.lua
index 5974005..a541aad 100644
--- a/tests/errhangtest.lua
+++ b/tests/errhangtest.lua
@@ -9,6 +9,6 @@ local coro = coroutine.create(function() end)
9-- however, this should raise an error, not hang the program... 9-- however, this should raise an error, not hang the program...
10print( pcall(linda.send,linda, 'test', "oh boy")) 10print( pcall(linda.send,linda, 'test', "oh boy"))
11print( pcall(linda.send,linda, 'test', coro)) 11print( pcall(linda.send,linda, 'test', coro))
12res = linda:receive('test') 12k,res = linda:receive('test')
13print( res) 13print( res)
14-- linda:send( 'test', coro) 14-- linda:send( 'test', coro)
diff --git a/tests/fifo.lua b/tests/fifo.lua
index 3c403fa..b68d8a4 100644
--- a/tests/fifo.lua
+++ b/tests/fifo.lua
@@ -23,7 +23,7 @@ local function FIFO()
23 linda:send( nil, my_channel, ... ) 23 linda:send( nil, my_channel, ... )
24 end, 24 end,
25 receive = function(self, timeout) 25 receive = function(self, timeout)
26 linda:receive( timeout, my_channel ) 26 return linda:receive( timeout, my_channel )
27 end 27 end
28 } 28 }
29end 29end
diff --git a/tests/linda_perf.lua b/tests/linda_perf.lua
index fff2670..87e0da7 100644
--- a/tests/linda_perf.lua
+++ b/tests/linda_perf.lua
@@ -3,24 +3,24 @@ lanes.configure()
3 3
4-- this lane eats items in the linda one by one 4-- this lane eats items in the linda one by one
5local eater = function( l, loop) 5local eater = function( l, loop)
6 local val, key = l:receive( "go") 6 local key, val = l:receive( "go")
7 for i = 1, loop do 7 for i = 1, loop do
8 local val, key = l:receive( "key") 8 local val, key = l:receive( "key")
9 --print( val) 9 --print( val)
10 end 10 end
11 -- print "loop is over" 11 -- print "loop is over"
12 val, key = l:receive( "done") 12 key, val = l:receive( "done")
13 -- print( val) 13 -- print( val)
14end 14end
15 15
16-- this lane eats items in the linda in batches 16-- this lane eats items in the linda in batches
17local batched = function( l, loop, batch) 17local batched = function( l, loop, batch)
18 local val, key = l:receive( "go") 18 local key, val = l:receive( "go")
19 for i = 1, loop/batch do 19 for i = 1, loop/batch do
20 l:receive( l.batched, "key", batch) 20 l:receive( l.batched, "key", batch)
21 end 21 end
22 print "loop is over" 22 print "loop is over"
23 val, key = l:receive( "done") 23 key, val = l:receive( "done")
24 print( val) 24 print( val)
25end 25end
26 26
diff --git a/tests/nameof.lua b/tests/nameof.lua
new file mode 100644
index 0000000..ed20a32
--- /dev/null
+++ b/tests/nameof.lua
@@ -0,0 +1,4 @@
1lanes = require "lanes".configure()
2
3print( lanes.nameof( string.sub))
4print( lanes.nameof( print))
diff --git a/tests/objects.lua b/tests/objects.lua
index 14cf9ba..eed02bf 100644
--- a/tests/objects.lua
+++ b/tests/objects.lua
@@ -19,7 +19,7 @@ local start_lane= lanes.gen( "io",
19 local mt1= getmetatable(obj1) 19 local mt1= getmetatable(obj1)
20 assert(mt1) 20 assert(mt1)
21 21
22 local obj2= linda:receive("") 22 local k, obj2= linda:receive("")
23 assert( obj2 ) 23 assert( obj2 )
24 local mt2= getmetatable(obj2) 24 local mt2= getmetatable(obj2)
25 assert(mt2) 25 assert(mt2)
diff --git a/tests/parallel_os_calls.lua b/tests/parallel_os_calls.lua
new file mode 100644
index 0000000..b8cffa1
--- /dev/null
+++ b/tests/parallel_os_calls.lua
@@ -0,0 +1,14 @@
1local lanes = require "lanes".configure(1)
2print( os.date())
3local linda = lanes.linda()
4lanes.gen("os,base", function() linda:receive(10, "null") print("finished_sleeping " .. os.date()) end)()
5lanes.gen("os,base", function() linda:receive(10, "null") print("finished_sleeping " .. os.date()) end)()
6lanes.gen("os,base", function() linda:receive(10, "null") print("finished_sleeping " .. os.date()) end)()
7lanes.gen("os,base", function() linda:receive(10, "null") print("finished_sleeping " .. os.date()) end)()
8
9--[[
10lanes.gen("os,base", function() os.execute('sleep 10 && echo finished_sleeping') print( os.date()) end)()
11lanes.gen("os,base", function() os.execute('sleep 10 && echo finished_sleeping') print( os.date()) end)()
12lanes.gen("os,base", function() os.execute('sleep 10 && echo finished_sleeping') print( os.date()) end)()
13lanes.gen("os,base", function() os.execute('sleep 10 && echo finished_sleeping') print( os.date()) end)()
14]]
diff --git a/tests/timer.lua b/tests/timer.lua
index c6f510b..84e6dec 100644
--- a/tests/timer.lua
+++ b/tests/timer.lua
@@ -35,7 +35,7 @@ local caught= {} -- { [T1]= bool, [T2]= bool }
35 35
36while true do 36while true do
37 io.stderr:write("waiting...\t") 37 io.stderr:write("waiting...\t")
38 local v,channel= linda:receive( 6.0, T1,T2 ) 38 local channel, v = linda:receive( 6.0, T1,T2 )
39 assert( channel==T1 or channel==T2 ) 39 assert( channel==T1 or channel==T2 )
40 caught[channel]= true 40 caught[channel]= true
41 41
@@ -89,6 +89,6 @@ assert( linda:get(T2) == nil )
89 89
90PRINT "...making sure no ticks are coming..." 90PRINT "...making sure no ticks are coming..."
91 91
92local v= linda:receive( 1.5, T1,T2 ) -- should not get any 92local k,v= linda:receive( 10, T1,T2 ) -- should not get any
93assert(v==nil) 93assert(v==nil)
94 94