aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/errhangtest.lua74
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 @@
1local lanes = require "lanes".configure{with_timers=false} 1local lanes = require "lanes".configure{with_timers=false}
2
3local linda = lanes.linda() 2local linda = lanes.linda()
4 3
5local 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...
6if 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"
12end
13
14if 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"
20end
6 21
7local fun = function() print "fun" end 22-- get/set a few values
8local t_in = { [fun] = fun, fun = fun } 23if 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"
32end
9 33
10-- send a string
11print( pcall(linda.send,linda, 'test', "oh boy"))
12-- send a table that contains a function 34-- send a table that contains a function
13print( pcall(linda.send,linda, 'test', t_in)) 35if 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"
44end
45
46-- send a string
47if 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"
53end
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...
16print( pcall(linda.send,linda, 'test', coro)) 57if true then
17k,str = linda:receive('test') -- read the contents successfully sent 58 print "\n#### coro send"
18print( str) -- "oh boy" 59 local coro = coroutine.create(function() end)
19k,t_out = linda:receive('test') -- read the contents successfully sent 60 print(pcall(linda.send, linda, 'test', coro))
20t_out.fun() -- "fun" 61 assert(linda:get("test") == nil)
21-- linda:send( 'test', coro) 62 print "OK"
22print "SUCCESS" \ No newline at end of file 63end
64
65-- done
66print "\nSUCCESS" \ No newline at end of file