diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/errhangtest.lua | 74 |
1 files changed, 59 insertions, 15 deletions
diff --git a/tests/errhangtest.lua b/tests/errhangtest.lua index d26dcef..811601e 100644 --- a/tests/errhangtest.lua +++ b/tests/errhangtest.lua | |||
@@ -1,22 +1,66 @@ | |||
1 | local lanes = require "lanes".configure{with_timers=false} | 1 | local lanes = require "lanes".configure{with_timers=false} |
2 | |||
3 | local linda = lanes.linda() | 2 | local linda = lanes.linda() |
4 | 3 | ||
5 | local coro = coroutine.create(function() end) | 4 | -- we are not allowed to send coroutines through a lane |
5 | -- however, this should raise an error, not hang the program... | ||
6 | if true then | ||
7 | print "#### coro set" | ||
8 | local coro = coroutine.create(function() end) | ||
9 | print(pcall(linda.set, linda, 'test', coro)) | ||
10 | assert(linda:get("test") == nil) | ||
11 | print "OK" | ||
12 | end | ||
13 | |||
14 | if true then | ||
15 | print "\n#### reserved sentinels" | ||
16 | print(pcall(linda.set, linda, lanes.cancel_error)) | ||
17 | print(pcall(linda.set, linda, linda.batched)) | ||
18 | assert(linda:get("test") == nil) | ||
19 | print "OK" | ||
20 | end | ||
6 | 21 | ||
7 | local fun = function() print "fun" end | 22 | -- get/set a few values |
8 | local t_in = { [fun] = fun, fun = fun } | 23 | if true then |
24 | print "\n#### set 3 -> receive batched" | ||
25 | local fun = function() print "function test ok" end | ||
26 | print(pcall(linda.set, linda, 'test', true, nil, fun)) | ||
27 | local k,b,n,f = linda:receive(linda.batched, 'test', 3) -- read back the contents | ||
28 | assert(linda:get("test") == nil) | ||
29 | print(k, b, n) | ||
30 | f() | ||
31 | print "OK" | ||
32 | end | ||
9 | 33 | ||
10 | -- send a string | ||
11 | print( pcall(linda.send,linda, 'test', "oh boy")) | ||
12 | -- send a table that contains a function | 34 | -- send a table that contains a function |
13 | print( pcall(linda.send,linda, 'test', t_in)) | 35 | if true then |
14 | -- we are not allowed to send coroutines through a lanes | 36 | print "\n#### send table with a function" |
37 | local fun = function() print "function test ok" end | ||
38 | local t_in = { [fun] = fun, fun = fun } | ||
39 | print(pcall(linda.send, linda, 'test', t_in)) | ||
40 | local k,t_out = linda:receive('test') -- read the contents successfully sent | ||
41 | t_out.fun() | ||
42 | -- TODO: t_out should contain a single entry, as [fun] = fun should have been discarded because functions are not acceptable keys | ||
43 | print "OK" | ||
44 | end | ||
45 | |||
46 | -- send a string | ||
47 | if true then | ||
48 | print "\n#### send string" | ||
49 | print(pcall(linda.send, linda, 'test', "string test ok")) | ||
50 | local k,str = linda:receive('test') -- read the contents successfully sent | ||
51 | print(str) | ||
52 | print "OK" | ||
53 | end | ||
54 | |||
55 | -- we are not allowed to send coroutines through a lane | ||
15 | -- however, this should raise an error, not hang the program... | 56 | -- however, this should raise an error, not hang the program... |
16 | print( pcall(linda.send,linda, 'test', coro)) | 57 | if true then |
17 | k,str = linda:receive('test') -- read the contents successfully sent | 58 | print "\n#### coro send" |
18 | print( str) -- "oh boy" | 59 | local coro = coroutine.create(function() end) |
19 | k,t_out = linda:receive('test') -- read the contents successfully sent | 60 | print(pcall(linda.send, linda, 'test', coro)) |
20 | t_out.fun() -- "fun" | 61 | assert(linda:get("test") == nil) |
21 | -- linda:send( 'test', coro) | 62 | print "OK" |
22 | print "SUCCESS" \ No newline at end of file | 63 | end |
64 | |||
65 | -- done | ||
66 | print "\nSUCCESS" \ No newline at end of file | ||