summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormoteus <mimir@newmail.ru>2013-12-26 18:10:40 +0400
committermoteus <mimir@newmail.ru>2013-12-26 18:10:40 +0400
commit5291caae5be68250a4d9aafa54fe2081ab2a6113 (patch)
tree48faae28c997bbb9552feb6fe60f350dee72714b
parent5982fd74baad6cdee2c536203afe6c435a2d02e9 (diff)
downloadlua-llthreads2-5291caae5be68250a4d9aafa54fe2081ab2a6113.tar.gz
lua-llthreads2-5291caae5be68250a4d9aafa54fe2081ab2a6113.tar.bz2
lua-llthreads2-5291caae5be68250a4d9aafa54fe2081ab2a6113.zip
Update tests.
-rw-r--r--README.md9
-rw-r--r--test/test_join_timeout.lua50
-rw-r--r--test/test_llthreads.lua24
-rw-r--r--test/test_threads.lua11
-rw-r--r--test/utils.lua63
5 files changed, 73 insertions, 84 deletions
diff --git a/README.md b/README.md
index 3721b90..b14d44d 100644
--- a/README.md
+++ b/README.md
@@ -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[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/moteus/lua-llthreads2/trend.png)](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)
34llthread.set_logger(function(msg) LOG.error(msg) end) 31llthread.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
39error("SOME ERROR") 33error("SOME ERROR")
40``` 34```
35
36[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/moteus/lua-llthreads2/trend.png)](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 @@
1local llthreads = require"llthreads" 1local llthreads = require"llthreads"
2 2local utils = require "utils"
3local sleep 3local sleep = utils.sleep
4local status, socket = pcall(require,"socket")
5if status then
6 sleep = function(secs)
7 return socket.sleep(secs)
8 end
9end
10
11if 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
18end
19
20if not sleep then
21 sleep = function(secs)
22 os.execute("sleep " .. tonumber(secs))
23 end
24end
25 4
26local include = [[ 5local include = [[
27local llthreads = require"llthreads" 6local llthreads = require"llthreads"
28 7]] .. utils.thread_init .. [[
29local sleep 8local sleep = require "utils".sleep
30local status, socket = pcall(require,"socket")
31if status then
32 sleep = function(secs)
33 return socket.sleep(secs)
34 end
35end
36
37if 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
44end
45
46if not sleep then
47 sleep = function(secs)
48 os.execute("sleep " .. tonumber(secs))
49 end
50end
51]] 9]]
52 10
53local thread = llthreads.new(include .. [[ 11local 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
21local llthreads = require"llthreads" 21local llthreads = require"llthreads"
22 22local sleep = require"utils".sleep
23local sleep
24local status, socket = pcall(require,"socket")
25if status then
26 sleep = function(secs)
27 return socket.sleep(secs)
28 end
29end
30
31if 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
38end
39
40if not sleep then
41 sleep = function(secs)
42 os.execute("sleep " .. tonumber(secs))
43 end
44end
45 23
46local function detached_thread(...) 24local 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
25local llthreads = require"llthreads" 25local llthreads = require"llthreads"
26local utils = require "utils"
26 27
27local num_threads = tonumber(arg[1] or 1000) 28local 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
30local thread_code = [[ 31local 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 @@
1local lua_version_t
2local 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]
12end
13
14local LUA_MAJOR, LUA_MINOR = lua_version()
15local IS_LUA_51 = (LUA_MAJOR == 5) and (LUA_MINOR == 1)
16local IS_LUA_52 = (LUA_MAJOR == 5) and (LUA_MINOR == 2)
17
18local LUA_INIT = "LUA_INIT"
19local LUA_INIT_VER
20if not IS_LUA_51 then
21 LUA_INIT_VER = LUA_INIT .. "_" .. LUA_MAJOR .. "_" .. LUA_MINOR
22end
23
24LUA_INIT = LUA_INIT_VER and os.getenv( LUA_INIT_VER ) or os.getenv( LUA_INIT ) or ""
25
26LUA_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
35end;]]
36
37local sleep
38local status, socket = pcall(require,"socket")
39if status then
40 sleep = function(secs)
41 return socket.sleep(secs)
42 end
43end
44
45if 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
52end
53
54if not sleep then
55 sleep = function(secs)
56 os.execute("sleep " .. tonumber(secs))
57 end
58end
59
60return {
61 thread_init = LUA_INIT,
62 sleep = sleep,
63}