From 92ec624951de2d344b28eb5262a3534822f6d6a7 Mon Sep 17 00:00:00 2001 From: moteus Date: Thu, 26 Dec 2013 14:34:13 +0400 Subject: Add. timeout parameter to thread:join() method --- test/test_join_timeout.lua | 64 ++++++++++++++++++++++++++++++++++++++++ test/test_register_llthreads.lua | 12 ++++++++ 2 files changed, 76 insertions(+) create mode 100644 test/test_join_timeout.lua create mode 100644 test/test_register_llthreads.lua (limited to 'test') 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 @@ +local llthreads = require"llthreads" + +local sleep +local status, socket = pcall(require,"socket") +if status then + sleep = function(secs) + return socket.sleep(secs) + end +end + +if not sleep then + local status, ztimer = pcall(require, "lzmq.timer") + if status then + sleep = function(secs) + ztimer.sleep(secs * 1000) + end + end +end + +if not sleep then + sleep = function(secs) + os.execute("sleep " .. tonumber(secs)) + end +end + +local include = [[ +local llthreads = require"llthreads" + +local sleep +local status, socket = pcall(require,"socket") +if status then + sleep = function(secs) + return socket.sleep(secs) + end +end + +if not sleep then + local status, ztimer = pcall(require, "lzmq.timer") + if status then + sleep = function(secs) + ztimer.sleep(secs * 1000) + end + end +end + +if not sleep then + sleep = function(secs) + os.execute("sleep " .. tonumber(secs)) + end +end +]] + +local thread = llthreads.new(include .. [[ + sleep(5) +]]) +thread:start() +local ok, err = thread:join(0) +print("thread:join(0): ", ok, err) +assert(ok == false) +assert(err == "timeout") + +print("thread:join(): ", thread:join()) +print("Done!") + 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 @@ +local llthreads = require "llthreads" +local thread = llthreads.new([[ + if not package.preload.llthreads then + print("llthreads does not register in thread") + os.exit(-1) + end + local ok, err = pcall(require, "llthreads") + if not ok then + print("can not load llthreads: ", err) + os.exit(-2) + end +]]):start():join() -- cgit v1.2.3-55-g6feb