aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Germain <bnt.germain@gmail.com>2019-04-19 14:58:25 +0200
committerBenoit Germain <bnt.germain@gmail.com>2019-04-19 14:58:25 +0200
commitbe1e9d37d9809ee55f26d811208fa64ea9b3785a (patch)
tree1b0122ed7e7f501c64814cdbbf03e5941dbab51c /tests
parent52934d46eed850c23a9b21125be73e987f34e772 (diff)
downloadlanes-be1e9d37d9809ee55f26d811208fa64ea9b3785a.tar.gz
lanes-be1e9d37d9809ee55f26d811208fa64ea9b3785a.tar.bz2
lanes-be1e9d37d9809ee55f26d811208fa64ea9b3785a.zip
lane:cancel internal code refactorization
Diffstat (limited to 'tests')
-rw-r--r--tests/basic.lua112
1 files changed, 56 insertions, 56 deletions
diff --git a/tests/basic.lua b/tests/basic.lua
index 7d42ad5..020fe78 100644
--- a/tests/basic.lua
+++ b/tests/basic.lua
@@ -26,7 +26,7 @@ local function PRINT(...)
26end 26end
27 27
28local gc_cb = function( name_, status_) 28local gc_cb = function( name_, status_)
29 PRINT( " ---> lane '" .. name_ .. "' collected with status " .. status_) 29 PRINT( " ---> lane '" .. name_ .. "' collected with status " .. status_)
30end 30end
31--gc_cb = nil 31--gc_cb = nil
32 32
@@ -77,7 +77,7 @@ local function task( a, b, c )
77end 77end
78 78
79local task_launch= lanes_gen( "", { globals={hey=true}, gc_cb = gc_cb}, task ) 79local task_launch= lanes_gen( "", { globals={hey=true}, gc_cb = gc_cb}, task )
80 -- base stdlibs, normal priority 80 -- base stdlibs, normal priority
81 81
82-- 'task_launch' is a factory of multithreaded tasks, we can launch several: 82-- 'task_launch' is a factory of multithreaded tasks, we can launch several:
83 83
@@ -155,12 +155,12 @@ limited:limit( "key", 1)
155-- [[################################################ 155-- [[################################################
156limited:send( "key", "hello") -- saturate linda 156limited:send( "key", "hello") -- saturate linda
157for k, v in pairs( limited:dump()) do 157for k, v in pairs( limited:dump()) do
158 PRINT("limited[" .. tostring( k) .. "] = " .. tostring( v)) 158 PRINT("limited[" .. tostring( k) .. "] = " .. tostring( v))
159end 159end
160local wait_send = function() 160local wait_send = function()
161 local a,b 161 local a,b
162 set_finalizer( function() print( "wait_send", a, b) end) 162 set_finalizer( function() print( "wait_send", a, b) end)
163 a,b = limited:send( "key", "bybye") -- infinite timeout, returns only when lane is cancelled 163 a,b = limited:send( "key", "bybye") -- infinite timeout, returns only when lane is cancelled
164end 164end
165 165
166local wait_send_lane = lanes.gen( "*", wait_send)() 166local wait_send_lane = lanes.gen( "*", wait_send)()
@@ -171,9 +171,9 @@ repeat until wait_send_lane.status == "cancelled"
171print "wait_send_lane is cancelled" 171print "wait_send_lane is cancelled"
172--################################################]] 172--################################################]]
173local wait_receive = function() 173local wait_receive = function()
174 local k, v 174 local k, v
175 set_finalizer( function() print( "wait_receive", k, v) end) 175 set_finalizer( function() print( "wait_receive", k, v) end)
176 k, v = limited:receive( "dummy") -- infinite timeout, returns only when lane is cancelled 176 k, v = limited:receive( "dummy") -- infinite timeout, returns only when lane is cancelled
177end 177end
178 178
179local wait_receive_lane = lanes.gen( "*", wait_receive)() 179local wait_receive_lane = lanes.gen( "*", wait_receive)()
@@ -184,9 +184,9 @@ repeat until wait_receive_lane.status == "cancelled"
184print "wait_receive_lane is cancelled" 184print "wait_receive_lane is cancelled"
185--################################################]] 185--################################################]]
186local wait_receive_batched = function() 186local wait_receive_batched = function()
187 local k, v1, v2 187 local k, v1, v2
188 set_finalizer( function() print( "wait_receive_batched", k, v1, v2) end) 188 set_finalizer( function() print( "wait_receive_batched", k, v1, v2) end)
189 k, v1, v2 = limited:receive( limited.batched, "dummy", 2) -- infinite timeout, returns only when lane is cancelled 189 k, v1, v2 = limited:receive( limited.batched, "dummy", 2) -- infinite timeout, returns only when lane is cancelled
190end 190end
191 191
192local wait_receive_batched_lane = lanes.gen( "*", wait_receive_batched)() 192local wait_receive_batched_lane = lanes.gen( "*", wait_receive_batched)()
@@ -206,7 +206,7 @@ PRINT( "\n\n", "---=== Communications ===---", "\n\n")
206local function WR(...) io.stderr:write(...) end 206local function WR(...) io.stderr:write(...) end
207 207
208local chunk= function( linda ) 208local chunk= function( linda )
209 set_debug_threadname "chunk" 209 set_debug_threadname "chunk"
210 local function receive() return linda:receive( "->" ) end 210 local function receive() return linda:receive( "->" ) end
211 local function send(...) linda:send( "<-", ... ) end 211 local function send(...) linda:send( "<-", ... ) end
212 212
@@ -254,9 +254,9 @@ local a,b,c= RECEIVE(), RECEIVE(), RECEIVE()
254 254
255print( "lane status: " .. t.status) 255print( "lane status: " .. t.status)
256if t.status == "error" then 256if t.status == "error" then
257 print( t:join()) 257 print( t:join())
258else 258else
259 WR( a..", "..b..", "..c.." received\n" ) 259 WR( a..", "..b..", "..c.." received\n" )
260end 260end
261 261
262assert( a==1 and b==2 and c==3 ) 262assert( a==1 and b==2 and c==3 )
@@ -286,50 +286,50 @@ linda: receive( 1, "wait")
286PRINT( "\n\n", "---=== Stdlib naming ===---", "\n\n") 286PRINT( "\n\n", "---=== Stdlib naming ===---", "\n\n")
287 287
288local function dump_g( _x) 288local function dump_g( _x)
289 set_debug_threadname "dump_g" 289 set_debug_threadname "dump_g"
290 assert(print) 290 assert(print)
291 print( "### dumping _G for '" .. _x .. "'") 291 print( "### dumping _G for '" .. _x .. "'")
292 for k, v in pairs( _G) do 292 for k, v in pairs( _G) do
293 print( "\t" .. k .. ": " .. type( v)) 293 print( "\t" .. k .. ": " .. type( v))
294 end 294 end
295 return true 295 return true
296end 296end
297 297
298local function io_os_f( _x) 298local function io_os_f( _x)
299 set_debug_threadname "io_os_f" 299 set_debug_threadname "io_os_f"
300 assert(print) 300 assert(print)
301 print( "### checking io and os libs existence for '" .. _x .. "'") 301 print( "### checking io and os libs existence for '" .. _x .. "'")
302 assert(io) 302 assert(io)
303 assert(os) 303 assert(os)
304 return true 304 return true
305end 305end
306 306
307local function coro_f( _x) 307local function coro_f( _x)
308 set_debug_threadname "coro_f" 308 set_debug_threadname "coro_f"
309 assert(print) 309 assert(print)
310 print( "### checking coroutine lib existence for '" .. _x .. "'") 310 print( "### checking coroutine lib existence for '" .. _x .. "'")
311 assert(coroutine) 311 assert(coroutine)
312 return true 312 return true
313end 313end
314 314
315assert.fails( function() lanes_gen( "xxx", {gc_cb = gc_cb}, io_os_f ) end ) 315assert.fails( function() lanes_gen( "xxx", {gc_cb = gc_cb}, io_os_f ) end )
316 316
317local stdlib_naming_tests = 317local stdlib_naming_tests =
318{ 318{
319 -- { "", dump_g}, 319 -- { "", dump_g},
320 -- { "coroutine", dump_g}, 320 -- { "coroutine", dump_g},
321 -- { "io", dump_g}, 321 -- { "io", dump_g},
322 -- { "bit32", dump_g}, 322 -- { "bit32", dump_g},
323 { "coroutine", coro_f}, 323 { "coroutine", coro_f},
324 { "*", io_os_f}, 324 { "*", io_os_f},
325 { "io,os", io_os_f}, 325 { "io,os", io_os_f},
326 { "io+os", io_os_f}, 326 { "io+os", io_os_f},
327 { "io,os,base", io_os_f}, 327 { "io,os,base", io_os_f},
328} 328}
329 329
330for _, t in ipairs( stdlib_naming_tests) do 330for _, t in ipairs( stdlib_naming_tests) do
331 local f= lanes_gen( t[1], {gc_cb = gc_cb}, t[2]) -- any delimiter will do 331 local f= lanes_gen( t[1], {gc_cb = gc_cb}, t[2]) -- any delimiter will do
332 assert( f(t[1])[1] ) 332 assert( f(t[1])[1] )
333end 333end
334 334
335collectgarbage() 335collectgarbage()
@@ -344,7 +344,7 @@ PRINT( "\n\n", "---=== Comms criss cross ===---", "\n\n")
344-- 344--
345local tc= lanes_gen( "io", {gc_cb = gc_cb}, 345local tc= lanes_gen( "io", {gc_cb = gc_cb},
346 function( linda, ch_in, ch_out ) 346 function( linda, ch_in, ch_out )
347 set_debug_threadname( "criss cross " .. ch_in .. " -> " .. ch_out) 347 set_debug_threadname( "criss cross " .. ch_in .. " -> " .. ch_out)
348 local function STAGE(str) 348 local function STAGE(str)
349 io.stderr:write( ch_in..": "..str.."\n" ) 349 io.stderr:write( ch_in..": "..str.."\n" )
350 linda:send( nil, ch_out, str ) 350 linda:send( nil, ch_out, str )
@@ -412,7 +412,7 @@ linda:send( "down", function(linda) linda:send( "up", "ready!" ) end,
412-- 412--
413local k,s= linda:receive( 1, "up" ) 413local k,s= linda:receive( 1, "up" )
414if t2.status == "error" then 414if t2.status == "error" then
415 print( "t2 error: " , t2:join()) 415 print( "t2 error: " , t2:join())
416end 416end
417PRINT(s) 417PRINT(s)
418assert( s=="ready!" ) 418assert( s=="ready!" )
@@ -440,13 +440,13 @@ PRINT( "\n\n", "---=== :join test ===---", "\n\n")
440 440
441local S= lanes_gen( "table", {gc_cb = gc_cb}, 441local S= lanes_gen( "table", {gc_cb = gc_cb},
442 function(arg) 442 function(arg)
443 set_debug_threadname "join test lane" 443 set_debug_threadname "join test lane"
444 set_finalizer( function() end) 444 set_finalizer( function() end)
445 aux= {} 445 aux= {}
446 for i, v in ipairs(arg) do 446 for i, v in ipairs(arg) do
447 table.insert (aux, 1, v) 447 table.insert (aux, 1, v)
448 end 448 end
449 -- unpack was renamed table.unpack in Lua 5.2: cater for both! 449 -- unpack was renamed table.unpack in Lua 5.2: cater for both!
450 return (unpack or table.unpack)(aux) 450 return (unpack or table.unpack)(aux)
451end ) 451end )
452 452
@@ -456,13 +456,13 @@ linda:receive(0.5, "gloupti")
456print( "joining with '" .. h:get_debug_threadname() .. "'") 456print( "joining with '" .. h:get_debug_threadname() .. "'")
457local a,b,c,d= h:join() 457local a,b,c,d= h:join()
458if h.status == "error" then 458if h.status == "error" then
459 print( h:get_debug_threadname(), "error: " , a, b, c, d) 459 print( h:get_debug_threadname(), "error: " , a, b, c, d)
460else 460else
461 print( h:get_debug_threadname(), a,b,c,d) 461 print( h:get_debug_threadname(), a,b,c,d)
462 assert(a==14) 462 assert(a==14)
463 assert(b==13) 463 assert(b==13)
464 assert(c==12) 464 assert(c==12)
465 assert(d==nil) 465 assert(d==nil)
466end 466end
467 467
468local nameof_type, nameof_name = lanes.nameof( print) 468local nameof_type, nameof_name = lanes.nameof( print)