diff options
| author | moteus <mimir@newmail.ru> | 2013-12-26 18:10:40 +0400 |
|---|---|---|
| committer | moteus <mimir@newmail.ru> | 2013-12-26 18:10:40 +0400 |
| commit | 5291caae5be68250a4d9aafa54fe2081ab2a6113 (patch) | |
| tree | 48faae28c997bbb9552feb6fe60f350dee72714b | |
| parent | 5982fd74baad6cdee2c536203afe6c435a2d02e9 (diff) | |
| download | lua-llthreads2-5291caae5be68250a4d9aafa54fe2081ab2a6113.tar.gz lua-llthreads2-5291caae5be68250a4d9aafa54fe2081ab2a6113.tar.bz2 lua-llthreads2-5291caae5be68250a4d9aafa54fe2081ab2a6113.zip | |
Update tests.
| -rw-r--r-- | README.md | 9 | ||||
| -rw-r--r-- | test/test_join_timeout.lua | 50 | ||||
| -rw-r--r-- | test/test_llthreads.lua | 24 | ||||
| -rw-r--r-- | test/test_threads.lua | 11 | ||||
| -rw-r--r-- | test/utils.lua | 63 |
5 files changed, 73 insertions, 84 deletions
| @@ -17,9 +17,6 @@ This is full dropin replacement for [llthreads](https://github.com/Neopallium/lu | |||
| 17 | * thread:join() method support arbitrary timeout on Windows platform | 17 | * thread:join() method support arbitrary timeout on Windows platform |
| 18 | * set_logger function allow logging errors (crash Lua VM) in current llthread's threads | 18 | * set_logger function allow logging errors (crash Lua VM) in current llthread's threads |
| 19 | 19 | ||
| 20 | [](https://bitdeli.com/free "Bitdeli Badge") | ||
| 21 | |||
| 22 | |||
| 23 | ##Usage | 20 | ##Usage |
| 24 | 21 | ||
| 25 | ### Use custom logger | 22 | ### Use custom logger |
| @@ -32,9 +29,9 @@ local LOG = require"log".new( | |||
| 32 | require "log.writer.net.zmq".new("tcp://127.0.0.1:5555") | 29 | require "log.writer.net.zmq".new("tcp://127.0.0.1:5555") |
| 33 | ) | 30 | ) |
| 34 | llthread.set_logger(function(msg) LOG.error(msg) end) | 31 | llthread.set_logger(function(msg) LOG.error(msg) end) |
| 35 | |||
| 36 | ... | ||
| 37 | |||
| 38 | -- This error with traceback will be passed to logger | 32 | -- This error with traceback will be passed to logger |
| 39 | error("SOME ERROR") | 33 | error("SOME ERROR") |
| 40 | ``` | 34 | ``` |
| 35 | |||
| 36 | [](https://bitdeli.com/free "Bitdeli Badge") | ||
| 37 | |||
diff --git a/test/test_join_timeout.lua b/test/test_join_timeout.lua index 5beac2b..085497f 100644 --- a/test/test_join_timeout.lua +++ b/test/test_join_timeout.lua | |||
| @@ -1,53 +1,11 @@ | |||
| 1 | local llthreads = require"llthreads" | 1 | local llthreads = require"llthreads" |
| 2 | 2 | local utils = require "utils" | |
| 3 | local sleep | 3 | local sleep = utils.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 | 4 | ||
| 26 | local include = [[ | 5 | local include = [[ |
| 27 | local llthreads = require"llthreads" | 6 | local llthreads = require"llthreads" |
| 28 | 7 | ]] .. utils.thread_init .. [[ | |
| 29 | local sleep | 8 | local sleep = require "utils".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 | ]] | 9 | ]] |
| 52 | 10 | ||
| 53 | local thread = llthreads.new(include .. [[ | 11 | local thread = llthreads.new(include .. [[ |
diff --git a/test/test_llthreads.lua b/test/test_llthreads.lua index 3474b9b..df8c6a2 100644 --- a/test/test_llthreads.lua +++ b/test/test_llthreads.lua | |||
| @@ -19,29 +19,7 @@ | |||
| 19 | -- THE SOFTWARE. | 19 | -- THE SOFTWARE. |
| 20 | 20 | ||
| 21 | local llthreads = require"llthreads" | 21 | local llthreads = require"llthreads" |
| 22 | 22 | local sleep = require"utils".sleep | |
| 23 | local sleep | ||
| 24 | local status, socket = pcall(require,"socket") | ||
| 25 | if status then | ||
| 26 | sleep = function(secs) | ||
| 27 | return socket.sleep(secs) | ||
| 28 | end | ||
| 29 | end | ||
| 30 | |||
| 31 | if not sleep then | ||
| 32 | local status, ztimer = pcall(require, "lzmq.timer") | ||
| 33 | if status then | ||
| 34 | sleep = function(secs) | ||
| 35 | ztimer.sleep(secs * 1000) | ||
| 36 | end | ||
| 37 | end | ||
| 38 | end | ||
| 39 | |||
| 40 | if not sleep then | ||
| 41 | sleep = function(secs) | ||
| 42 | os.execute("sleep " .. tonumber(secs)) | ||
| 43 | end | ||
| 44 | end | ||
| 45 | 23 | ||
| 46 | local function detached_thread(...) | 24 | local function detached_thread(...) |
| 47 | local thread = llthreads.new([[ print("print_detached_thread:", ...) ]], ...) | 25 | local thread = llthreads.new([[ print("print_detached_thread:", ...) ]], ...) |
diff --git a/test/test_threads.lua b/test/test_threads.lua index 467526e..459604d 100644 --- a/test/test_threads.lua +++ b/test/test_threads.lua | |||
| @@ -23,19 +23,12 @@ | |||
| 23 | -- luajit sub_threads.lua | 23 | -- luajit sub_threads.lua |
| 24 | 24 | ||
| 25 | local llthreads = require"llthreads" | 25 | local llthreads = require"llthreads" |
| 26 | local utils = require "utils" | ||
| 26 | 27 | ||
| 27 | local num_threads = tonumber(arg[1] or 1000) | 28 | local num_threads = tonumber(arg[1] or 1000) |
| 28 | 29 | ||
| 29 | -- level 0 string literal enclosure [[ ]] of child execution code | 30 | -- level 0 string literal enclosure [[ ]] of child execution code |
| 30 | local thread_code = [[ | 31 | local thread_code = utils.thread_init .. [[ |
| 31 | local lua_init = os.getenv("lua_init") | ||
| 32 | if lua_init and #lua_init > 0 then | ||
| 33 | if lua_init:sub(1,1) == '@' then | ||
| 34 | dofile(lua_init:sub(2)) | ||
| 35 | else | ||
| 36 | assert((loadstring or load)(lua_init))() | ||
| 37 | end | ||
| 38 | end | ||
| 39 | 32 | ||
| 40 | local num_threads = ... | 33 | local num_threads = ... |
| 41 | print("CHILD: received from ROOT params:", ...) | 34 | print("CHILD: received from ROOT params:", ...) |
diff --git a/test/utils.lua b/test/utils.lua new file mode 100644 index 0000000..d9b5fe5 --- /dev/null +++ b/test/utils.lua | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | local lua_version_t | ||
| 2 | local function lua_version() | ||
| 3 | if not lua_version_t then | ||
| 4 | local version = rawget(_G,"_VERSION") | ||
| 5 | local maj,min = version:match("^Lua (%d+)%.(%d+)$") | ||
| 6 | if maj then lua_version_t = {tonumber(maj),tonumber(min)} | ||
| 7 | elseif not math.mod then lua_version_t = {5,2} | ||
| 8 | elseif table.pack and not pack then lua_version_t = {5,2} | ||
| 9 | else lua_version_t = {5,2} end | ||
| 10 | end | ||
| 11 | return lua_version_t[1], lua_version_t[2] | ||
| 12 | end | ||
| 13 | |||
| 14 | local LUA_MAJOR, LUA_MINOR = lua_version() | ||
| 15 | local IS_LUA_51 = (LUA_MAJOR == 5) and (LUA_MINOR == 1) | ||
| 16 | local IS_LUA_52 = (LUA_MAJOR == 5) and (LUA_MINOR == 2) | ||
| 17 | |||
| 18 | local LUA_INIT = "LUA_INIT" | ||
| 19 | local LUA_INIT_VER | ||
| 20 | if not IS_LUA_51 then | ||
| 21 | LUA_INIT_VER = LUA_INIT .. "_" .. LUA_MAJOR .. "_" .. LUA_MINOR | ||
| 22 | end | ||
| 23 | |||
| 24 | LUA_INIT = LUA_INIT_VER and os.getenv( LUA_INIT_VER ) or os.getenv( LUA_INIT ) or "" | ||
| 25 | |||
| 26 | LUA_INIT = [[do | ||
| 27 | local lua_init = ]] .. ("%q"):format(LUA_INIT) .. [[ | ||
| 28 | if lua_init and #lua_init > 0 then | ||
| 29 | if lua_init:sub(1,1) == '@' then | ||
| 30 | dofile(lua_init:sub(2)) | ||
| 31 | else | ||
| 32 | assert((loadstring or load)(lua_init))() | ||
| 33 | end | ||
| 34 | end | ||
| 35 | end;]] | ||
| 36 | |||
| 37 | local sleep | ||
| 38 | local status, socket = pcall(require,"socket") | ||
| 39 | if status then | ||
| 40 | sleep = function(secs) | ||
| 41 | return socket.sleep(secs) | ||
| 42 | end | ||
| 43 | end | ||
| 44 | |||
| 45 | if not sleep then | ||
| 46 | local status, ztimer = pcall(require, "lzmq.timer") | ||
| 47 | if status then | ||
| 48 | sleep = function(secs) | ||
| 49 | ztimer.sleep(secs * 1000) | ||
| 50 | end | ||
| 51 | end | ||
| 52 | end | ||
| 53 | |||
| 54 | if not sleep then | ||
| 55 | sleep = function(secs) | ||
| 56 | os.execute("sleep " .. tonumber(secs)) | ||
| 57 | end | ||
| 58 | end | ||
| 59 | |||
| 60 | return { | ||
| 61 | thread_init = LUA_INIT, | ||
| 62 | sleep = sleep, | ||
| 63 | } | ||
