diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/test_join_timeout.lua | 64 | ||||
| -rw-r--r-- | test/test_register_llthreads.lua | 12 |
2 files changed, 76 insertions, 0 deletions
diff --git a/test/test_join_timeout.lua b/test/test_join_timeout.lua new file mode 100644 index 0000000..5beac2b --- /dev/null +++ b/test/test_join_timeout.lua | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | local llthreads = require"llthreads" | ||
| 2 | |||
| 3 | local sleep | ||
| 4 | local status, socket = pcall(require,"socket") | ||
| 5 | if status then | ||
| 6 | sleep = function(secs) | ||
| 7 | return socket.sleep(secs) | ||
| 8 | end | ||
| 9 | end | ||
| 10 | |||
| 11 | if not sleep then | ||
| 12 | local status, ztimer = pcall(require, "lzmq.timer") | ||
| 13 | if status then | ||
| 14 | sleep = function(secs) | ||
| 15 | ztimer.sleep(secs * 1000) | ||
| 16 | end | ||
| 17 | end | ||
| 18 | end | ||
| 19 | |||
| 20 | if not sleep then | ||
| 21 | sleep = function(secs) | ||
| 22 | os.execute("sleep " .. tonumber(secs)) | ||
| 23 | end | ||
| 24 | end | ||
| 25 | |||
| 26 | local include = [[ | ||
| 27 | local llthreads = require"llthreads" | ||
| 28 | |||
| 29 | local sleep | ||
| 30 | local status, socket = pcall(require,"socket") | ||
| 31 | if status then | ||
| 32 | sleep = function(secs) | ||
| 33 | return socket.sleep(secs) | ||
| 34 | end | ||
| 35 | end | ||
| 36 | |||
| 37 | if not sleep then | ||
| 38 | local status, ztimer = pcall(require, "lzmq.timer") | ||
| 39 | if status then | ||
| 40 | sleep = function(secs) | ||
| 41 | ztimer.sleep(secs * 1000) | ||
| 42 | end | ||
| 43 | end | ||
| 44 | end | ||
| 45 | |||
| 46 | if not sleep then | ||
| 47 | sleep = function(secs) | ||
| 48 | os.execute("sleep " .. tonumber(secs)) | ||
| 49 | end | ||
| 50 | end | ||
| 51 | ]] | ||
| 52 | |||
| 53 | local thread = llthreads.new(include .. [[ | ||
| 54 | sleep(5) | ||
| 55 | ]]) | ||
| 56 | thread:start() | ||
| 57 | local ok, err = thread:join(0) | ||
| 58 | print("thread:join(0): ", ok, err) | ||
| 59 | assert(ok == false) | ||
| 60 | assert(err == "timeout") | ||
| 61 | |||
| 62 | print("thread:join(): ", thread:join()) | ||
| 63 | print("Done!") | ||
| 64 | |||
diff --git a/test/test_register_llthreads.lua b/test/test_register_llthreads.lua new file mode 100644 index 0000000..f02bf86 --- /dev/null +++ b/test/test_register_llthreads.lua | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | local llthreads = require "llthreads" | ||
| 2 | local thread = llthreads.new([[ | ||
| 3 | if not package.preload.llthreads then | ||
| 4 | print("llthreads does not register in thread") | ||
| 5 | os.exit(-1) | ||
| 6 | end | ||
| 7 | local ok, err = pcall(require, "llthreads") | ||
| 8 | if not ok then | ||
| 9 | print("can not load llthreads: ", err) | ||
| 10 | os.exit(-2) | ||
| 11 | end | ||
| 12 | ]]):start():join() | ||
