diff options
| author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-04-15 09:44:45 +0200 |
|---|---|---|
| committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-04-15 09:44:45 +0200 |
| commit | 111790701a45e074de2e8e5d8d4831ac285e22b0 (patch) | |
| tree | 3f9233015e61f605e22e9fd0d4c8642a8e7000cd /tests | |
| parent | 69d40c81d8343a1af7e0fe61fbf20a4cf5880c25 (diff) | |
| download | lanes-111790701a45e074de2e8e5d8d4831ac285e22b0.tar.gz lanes-111790701a45e074de2e8e5d8d4831ac285e22b0.tar.bz2 lanes-111790701a45e074de2e8e5d8d4831ac285e22b0.zip | |
C++ migration: keeper_call returns a std::optional
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 | ||
