aboutsummaryrefslogtreecommitdiff
path: root/tests/basic.lua
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/basic.lua29
1 files changed, 15 insertions, 14 deletions
diff --git a/tests/basic.lua b/tests/basic.lua
index 170e821..f393175 100644
--- a/tests/basic.lua
+++ b/tests/basic.lua
@@ -163,7 +163,7 @@ PRINT(" "..st)
163assert(st == "cancelled", "st is '" .. st .. "' instead of 'cancelled'") 163assert(st == "cancelled", "st is '" .. st .. "' instead of 'cancelled'")
164 164
165-- cancellation of lanes waiting on a linda 165-- cancellation of lanes waiting on a linda
166local limited = lanes_linda("limited") 166local limited = lanes_linda{name = "limited"}
167assert.fails(function() limited:limit("key", -1) end) 167assert.fails(function() limited:limit("key", -1) end)
168assert.failsnot(function() limited:limit("key", 1) end) 168assert.failsnot(function() limited:limit("key", 1) end)
169-- [[################################################ 169-- [[################################################
@@ -209,7 +209,7 @@ PRINT "wait_receive_lane is cancelled"
209local wait_receive_batched = function() 209local wait_receive_batched = function()
210 local k, v1, v2 210 local k, v1, v2
211 set_finalizer(function() print("wait_receive_batched", k, v1, v2) end) 211 set_finalizer(function() print("wait_receive_batched", k, v1, v2) end)
212 k, v1, v2 = limited:receive(limited.batched, "dummy", 2) -- infinite timeout, returns only when lane is cancelled 212 k, v1, v2 = limited:receive_batched("dummy", 2) -- infinite timeout, returns only when lane is cancelled
213end 213end
214 214
215local wait_receive_batched_lane = lanes.gen("*", { name = 'auto' }, wait_receive_batched)() 215local wait_receive_batched_lane = lanes.gen("*", { name = 'auto' }, wait_receive_batched)()
@@ -255,7 +255,7 @@ local chunk= function(linda)
255 WR("chunk ", "Lane ends!\n") 255 WR("chunk ", "Lane ends!\n")
256end 256end
257 257
258local linda = lanes_linda("communications") 258local linda = lanes_linda{name = "communications"}
259assert(type(linda) == "userdata" and tostring(linda) == "Linda: communications") 259assert(type(linda) == "userdata" and tostring(linda) == "Linda: communications")
260 -- 260 --
261 -- ["->"] master -> slave 261 -- ["->"] master -> slave
@@ -273,7 +273,7 @@ local b,x,y,z,w = linda:get("<->", 4)
273assert(b == 3 and x == "x" and y == "y" and z == "z" and w == nil) 273assert(b == 3 and x == "x" and y == "y" and z == "z" and w == nil)
274local k, x = linda:receive("<->") 274local k, x = linda:receive("<->")
275assert(k == "<->" and x == "x") 275assert(k == "<->" and x == "x")
276local k,y,z = linda:receive(linda.batched, "<->", 2) 276local k,y,z = linda:receive_batched("<->", 2)
277assert(k == "<->" and y == "y" and z == "z") 277assert(k == "<->" and y == "y" and z == "z")
278linda:set("<->") 278linda:set("<->")
279local b,x,y,z,w = linda:get("<->", 4) 279local b,x,y,z,w = linda:get("<->", 4)
@@ -410,7 +410,7 @@ local tc = lanes.gen("io", { name = 'auto', gc_cb = gc_cb },
410 end 410 end
411) 411)
412 412
413local linda= lanes_linda("criss cross") 413local linda= lanes_linda{name = "criss cross"}
414 414
415local a,b= tc(linda, "A","B"), tc(linda, "B","A") -- launching two lanes, twisted comms 415local a,b= tc(linda, "A","B"), tc(linda, "B","A") -- launching two lanes, twisted comms
416 416
@@ -461,7 +461,7 @@ local function chunk2(linda)
461 linda:send("up", function() return ":)" end, "ok2") 461 linda:send("up", function() return ":)" end, "ok2")
462end 462end
463 463
464local linda = lanes_linda("auto") 464local linda = lanes_linda{name = "auto"}
465local t2 = lanes.gen("debug,string,io", { name = 'auto', gc_cb = gc_cb }, chunk2)(linda) -- prepare & launch 465local t2 = lanes.gen("debug,string,io", { name = 'auto', gc_cb = gc_cb }, chunk2)(linda) -- prepare & launch
466linda:send("down", function(linda) linda:send("up", "ready!") end, 466linda:send("down", function(linda) linda:send("up", "ready!") end,
467 "ok") 467 "ok")
@@ -507,19 +507,20 @@ local S = lanes.gen("table", { name = 'auto', gc_cb = gc_cb },
507 return (unpack or table.unpack)(aux) 507 return (unpack or table.unpack)(aux)
508end) 508end)
509 509
510h= S { 12, 13, 14 } -- execution starts, h[1..3] will get the return values 510h = S { 12, 13, 14 } -- execution starts, h[1..3] will get the return values
511-- wait a bit so that the lane has a chance to set its debug name 511-- wait a bit so that the lane has a chance to set its debug name
512SLEEP(0.5) 512SLEEP(0.5)
513print("joining with '" .. h:get_threadname() .. "'") 513print("joining with '" .. h:get_threadname() .. "'")
514local a,b,c,d= h:join() 514local r,a,b,c,d= h:join()
515if h.status == "error" then 515if h.status == "error" then
516 print(h:get_threadname(), "error: " , a, b, c, d) 516 print(h:get_threadname(), "error: " , r, a, b, c, d)
517else 517else
518 print(h:get_threadname(), a,b,c,d) 518 print(h:get_threadname(), r,a,b,c,d)
519 assert(a==14) 519 assert(r == true)
520 assert(b==13) 520 assert(a == 14)
521 assert(c==12) 521 assert(b == 13)
522 assert(d==nil) 522 assert(c == 12)
523 assert(d == nil)
523end 524end
524 525
525local nameof_type, nameof_name = lanes.nameof(print) 526local nameof_type, nameof_name = lanes.nameof(print)