aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authormoteus <mimir@newmail.ru>2013-12-26 14:34:13 +0400
committermoteus <mimir@newmail.ru>2013-12-26 14:45:02 +0400
commit92ec624951de2d344b28eb5262a3534822f6d6a7 (patch)
tree793f5c5ab09f05e0462489678b5186bb588d0b4a /test
parent7b90a331bf1caecfa1ba1e2f3e7f87fa01c389b9 (diff)
downloadlua-llthreads2-92ec624951de2d344b28eb5262a3534822f6d6a7.tar.gz
lua-llthreads2-92ec624951de2d344b28eb5262a3534822f6d6a7.tar.bz2
lua-llthreads2-92ec624951de2d344b28eb5262a3534822f6d6a7.zip
Add. timeout parameter to thread:join() method
Diffstat (limited to 'test')
-rw-r--r--test/test_join_timeout.lua64
-rw-r--r--test/test_register_llthreads.lua12
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 @@
1local llthreads = require"llthreads"
2
3local 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
26local include = [[
27local llthreads = require"llthreads"
28
29local 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]]
52
53local thread = llthreads.new(include .. [[
54 sleep(5)
55]])
56thread:start()
57local ok, err = thread:join(0)
58print("thread:join(0): ", ok, err)
59assert(ok == false)
60assert(err == "timeout")
61
62print("thread:join(): ", thread:join())
63print("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 @@
1local llthreads = require "llthreads"
2local 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()