diff options
Diffstat (limited to '')
-rw-r--r-- | tests/basic.lua | 29 |
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) | |||
163 | assert(st == "cancelled", "st is '" .. st .. "' instead of 'cancelled'") | 163 | assert(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 |
166 | local limited = lanes_linda("limited") | 166 | local limited = lanes_linda{name = "limited"} |
167 | assert.fails(function() limited:limit("key", -1) end) | 167 | assert.fails(function() limited:limit("key", -1) end) |
168 | assert.failsnot(function() limited:limit("key", 1) end) | 168 | assert.failsnot(function() limited:limit("key", 1) end) |
169 | -- [[################################################ | 169 | -- [[################################################ |
@@ -209,7 +209,7 @@ PRINT "wait_receive_lane is cancelled" | |||
209 | local wait_receive_batched = function() | 209 | local 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 |
213 | end | 213 | end |
214 | 214 | ||
215 | local wait_receive_batched_lane = lanes.gen("*", { name = 'auto' }, wait_receive_batched)() | 215 | local 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") |
256 | end | 256 | end |
257 | 257 | ||
258 | local linda = lanes_linda("communications") | 258 | local linda = lanes_linda{name = "communications"} |
259 | assert(type(linda) == "userdata" and tostring(linda) == "Linda: communications") | 259 | assert(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) | |||
273 | assert(b == 3 and x == "x" and y == "y" and z == "z" and w == nil) | 273 | assert(b == 3 and x == "x" and y == "y" and z == "z" and w == nil) |
274 | local k, x = linda:receive("<->") | 274 | local k, x = linda:receive("<->") |
275 | assert(k == "<->" and x == "x") | 275 | assert(k == "<->" and x == "x") |
276 | local k,y,z = linda:receive(linda.batched, "<->", 2) | 276 | local k,y,z = linda:receive_batched("<->", 2) |
277 | assert(k == "<->" and y == "y" and z == "z") | 277 | assert(k == "<->" and y == "y" and z == "z") |
278 | linda:set("<->") | 278 | linda:set("<->") |
279 | local b,x,y,z,w = linda:get("<->", 4) | 279 | local 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 | ||
413 | local linda= lanes_linda("criss cross") | 413 | local linda= lanes_linda{name = "criss cross"} |
414 | 414 | ||
415 | local a,b= tc(linda, "A","B"), tc(linda, "B","A") -- launching two lanes, twisted comms | 415 | local 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") |
462 | end | 462 | end |
463 | 463 | ||
464 | local linda = lanes_linda("auto") | 464 | local linda = lanes_linda{name = "auto"} |
465 | local t2 = lanes.gen("debug,string,io", { name = 'auto', gc_cb = gc_cb }, chunk2)(linda) -- prepare & launch | 465 | local t2 = lanes.gen("debug,string,io", { name = 'auto', gc_cb = gc_cb }, chunk2)(linda) -- prepare & launch |
466 | linda:send("down", function(linda) linda:send("up", "ready!") end, | 466 | linda: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) |
508 | end) | 508 | end) |
509 | 509 | ||
510 | h= S { 12, 13, 14 } -- execution starts, h[1..3] will get the return values | 510 | h = 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 |
512 | SLEEP(0.5) | 512 | SLEEP(0.5) |
513 | print("joining with '" .. h:get_threadname() .. "'") | 513 | print("joining with '" .. h:get_threadname() .. "'") |
514 | local a,b,c,d= h:join() | 514 | local r,a,b,c,d= h:join() |
515 | if h.status == "error" then | 515 | if 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) |
517 | else | 517 | else |
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) | ||
523 | end | 524 | end |
524 | 525 | ||
525 | local nameof_type, nameof_name = lanes.nameof(print) | 526 | local nameof_type, nameof_name = lanes.nameof(print) |