diff options
Diffstat (limited to 'tests/basic.lua')
-rw-r--r-- | tests/basic.lua | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/tests/basic.lua b/tests/basic.lua index 068dc25..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 | -- [[################################################ |
@@ -173,42 +173,51 @@ for k, v in pairs(limited:dump()) do | |||
173 | end | 173 | end |
174 | local wait_send = function() | 174 | local wait_send = function() |
175 | local a,b | 175 | local a,b |
176 | set_finalizer(function() print("wait_send", a, b) end) | 176 | set_finalizer(function(err, stack_tbl) print("wait_send", a, b, " -> ", tostring(err)) end) |
177 | print("in wait_send") | ||
177 | a,b = limited:send("key", "bybye") -- infinite timeout, returns only when lane is cancelled | 178 | a,b = limited:send("key", "bybye") -- infinite timeout, returns only when lane is cancelled |
178 | end | 179 | end |
179 | 180 | ||
180 | local wait_send_lane = lanes.gen("*", { name = 'auto' }, wait_send)() | 181 | local wait_send_lane = lanes.gen("*", { name = 'auto' }, wait_send)() |
181 | repeat until wait_send_lane.status == "waiting" | 182 | repeat |
182 | print "wait_send_lane is waiting" | 183 | io.stderr:write('!') |
184 | -- currently mingw64 builds can deadlock if we cancel the lane too early (before the linda blocks, at it causes the linda condvar not to be signalled) | ||
185 | lanes.sleep(0.1) | ||
186 | until wait_send_lane.status == "waiting" | ||
187 | PRINT "wait_send_lane is waiting" | ||
183 | wait_send_lane:cancel() -- hard cancel, 0 timeout | 188 | wait_send_lane:cancel() -- hard cancel, 0 timeout |
184 | repeat until wait_send_lane.status == "cancelled" | 189 | repeat until wait_send_lane.status == "cancelled" |
185 | print "wait_send_lane is cancelled" | 190 | PRINT "wait_send_lane is cancelled" |
186 | --################################################]] | 191 | --################################################]] |
187 | local wait_receive = function() | 192 | local wait_receive = function() |
188 | local k, v | 193 | local k, v |
189 | set_finalizer(function() print("wait_receive", k, v) end) | 194 | set_finalizer(function(err, stack_tbl) print("wait_receive", k, v, " -> ", tostring(err)) end) |
190 | k, v = limited:receive("dummy") -- infinite timeout, returns only when lane is cancelled | 195 | k, v = limited:receive("dummy") -- infinite timeout, returns only when lane is cancelled |
191 | end | 196 | end |
192 | 197 | ||
193 | local wait_receive_lane = lanes.gen("*", { name = 'auto' }, wait_receive)() | 198 | local wait_receive_lane = lanes.gen("*", { name = 'auto' }, wait_receive)() |
194 | repeat until wait_receive_lane.status == "waiting" | 199 | repeat |
195 | print "wait_receive_lane is waiting" | 200 | io.stderr:write('!') |
201 | -- currently mingw64 builds can deadlock if we cancel the lane too early (before the linda blocks, at it causes the linda condvar not to be signalled) | ||
202 | lanes.sleep(0.1) | ||
203 | until wait_receive_lane.status == "waiting" | ||
204 | PRINT "wait_receive_lane is waiting" | ||
196 | wait_receive_lane:cancel() -- hard cancel, 0 timeout | 205 | wait_receive_lane:cancel() -- hard cancel, 0 timeout |
197 | repeat until wait_receive_lane.status == "cancelled" | 206 | repeat until wait_receive_lane.status == "cancelled" |
198 | print "wait_receive_lane is cancelled" | 207 | PRINT "wait_receive_lane is cancelled" |
199 | --################################################]] | 208 | --################################################]] |
200 | local wait_receive_batched = function() | 209 | local wait_receive_batched = function() |
201 | local k, v1, v2 | 210 | local k, v1, v2 |
202 | set_finalizer(function() print("wait_receive_batched", k, v1, v2) end) | 211 | set_finalizer(function() print("wait_receive_batched", k, v1, v2) end) |
203 | 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 |
204 | end | 213 | end |
205 | 214 | ||
206 | 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)() |
207 | repeat until wait_receive_batched_lane.status == "waiting" | 216 | repeat until wait_receive_batched_lane.status == "waiting" |
208 | print "wait_receive_batched_lane is waiting" | 217 | PRINT "wait_receive_batched_lane is waiting" |
209 | wait_receive_batched_lane:cancel() -- hard cancel, 0 timeout | 218 | wait_receive_batched_lane:cancel() -- hard cancel, 0 timeout |
210 | repeat until wait_receive_batched_lane.status == "cancelled" | 219 | repeat until wait_receive_batched_lane.status == "cancelled" |
211 | print "wait_receive_batched_lane is cancelled" | 220 | PRINT "wait_receive_batched_lane is cancelled" |
212 | --################################################]] | 221 | --################################################]] |
213 | 222 | ||
214 | -- ################################################################################################## | 223 | -- ################################################################################################## |
@@ -246,7 +255,7 @@ local chunk= function(linda) | |||
246 | WR("chunk ", "Lane ends!\n") | 255 | WR("chunk ", "Lane ends!\n") |
247 | end | 256 | end |
248 | 257 | ||
249 | local linda = lanes_linda("communications") | 258 | local linda = lanes_linda{name = "communications"} |
250 | assert(type(linda) == "userdata" and tostring(linda) == "Linda: communications") | 259 | assert(type(linda) == "userdata" and tostring(linda) == "Linda: communications") |
251 | -- | 260 | -- |
252 | -- ["->"] master -> slave | 261 | -- ["->"] master -> slave |
@@ -264,7 +273,7 @@ local b,x,y,z,w = linda:get("<->", 4) | |||
264 | 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) |
265 | local k, x = linda:receive("<->") | 274 | local k, x = linda:receive("<->") |
266 | assert(k == "<->" and x == "x") | 275 | assert(k == "<->" and x == "x") |
267 | local k,y,z = linda:receive(linda.batched, "<->", 2) | 276 | local k,y,z = linda:receive_batched("<->", 2) |
268 | assert(k == "<->" and y == "y" and z == "z") | 277 | assert(k == "<->" and y == "y" and z == "z") |
269 | linda:set("<->") | 278 | linda:set("<->") |
270 | local b,x,y,z,w = linda:get("<->", 4) | 279 | local b,x,y,z,w = linda:get("<->", 4) |
@@ -401,7 +410,7 @@ local tc = lanes.gen("io", { name = 'auto', gc_cb = gc_cb }, | |||
401 | end | 410 | end |
402 | ) | 411 | ) |
403 | 412 | ||
404 | local linda= lanes_linda("criss cross") | 413 | local linda= lanes_linda{name = "criss cross"} |
405 | 414 | ||
406 | 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 |
407 | 416 | ||
@@ -437,7 +446,7 @@ local function chunk2(linda) | |||
437 | assert(config.strip_functions and info.short_src=="?" or string.match(info.short_src, "^.*basic.lua$"), "bad info.short_src") | 446 | assert(config.strip_functions and info.short_src=="?" or string.match(info.short_src, "^.*basic.lua$"), "bad info.short_src") |
438 | -- These vary so let's not be picky (they're there..) | 447 | -- These vary so let's not be picky (they're there..) |
439 | -- | 448 | -- |
440 | assert(info.linedefined == 422, "bad linedefined") -- start of 'chunk2' | 449 | assert(info.linedefined == 431, "bad linedefined") -- start of 'chunk2' |
441 | assert(config.strip_functions and info.currentline==-1 or info.currentline > info.linedefined, "bad currentline") -- line of 'debug.getinfo' | 450 | assert(config.strip_functions and info.currentline==-1 or info.currentline > info.linedefined, "bad currentline") -- line of 'debug.getinfo' |
442 | assert(info.lastlinedefined > info.currentline, "bad lastlinedefined") -- end of 'chunk2' | 451 | assert(info.lastlinedefined > info.currentline, "bad lastlinedefined") -- end of 'chunk2' |
443 | local k,func= linda:receive("down") | 452 | local k,func= linda:receive("down") |
@@ -452,7 +461,7 @@ local function chunk2(linda) | |||
452 | linda:send("up", function() return ":)" end, "ok2") | 461 | linda:send("up", function() return ":)" end, "ok2") |
453 | end | 462 | end |
454 | 463 | ||
455 | local linda = lanes_linda("auto") | 464 | local linda = lanes_linda{name = "auto"} |
456 | 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 |
457 | linda:send("down", function(linda) linda:send("up", "ready!") end, | 466 | linda:send("down", function(linda) linda:send("up", "ready!") end, |
458 | "ok") | 467 | "ok") |
@@ -460,7 +469,7 @@ linda:send("down", function(linda) linda:send("up", "ready!") end, | |||
460 | -- | 469 | -- |
461 | local k,s= linda:receive(1, "up") | 470 | local k,s= linda:receive(1, "up") |
462 | if t2.status == "error" then | 471 | if t2.status == "error" then |
463 | print("t2 error: " , t2:join()) | 472 | PRINT("t2 error: " , t2:join()) |
464 | end | 473 | end |
465 | PRINT(s) | 474 | PRINT(s) |
466 | assert(s=="ready!") | 475 | assert(s=="ready!") |
@@ -498,19 +507,20 @@ local S = lanes.gen("table", { name = 'auto', gc_cb = gc_cb }, | |||
498 | return (unpack or table.unpack)(aux) | 507 | return (unpack or table.unpack)(aux) |
499 | end) | 508 | end) |
500 | 509 | ||
501 | 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 |
502 | -- 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 |
503 | SLEEP(0.5) | 512 | SLEEP(0.5) |
504 | print("joining with '" .. h:get_threadname() .. "'") | 513 | print("joining with '" .. h:get_threadname() .. "'") |
505 | local a,b,c,d= h:join() | 514 | local r,a,b,c,d= h:join() |
506 | if h.status == "error" then | 515 | if h.status == "error" then |
507 | print(h:get_threadname(), "error: " , a, b, c, d) | 516 | print(h:get_threadname(), "error: " , r, a, b, c, d) |
508 | else | 517 | else |
509 | print(h:get_threadname(), a,b,c,d) | 518 | print(h:get_threadname(), r,a,b,c,d) |
510 | assert(a==14) | 519 | assert(r == true) |
511 | assert(b==13) | 520 | assert(a == 14) |
512 | assert(c==12) | 521 | assert(b == 13) |
513 | assert(d==nil) | 522 | assert(c == 12) |
523 | assert(d == nil) | ||
514 | end | 524 | end |
515 | 525 | ||
516 | local nameof_type, nameof_name = lanes.nameof(print) | 526 | local nameof_type, nameof_name = lanes.nameof(print) |