mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-22 02:53:09 +00:00
Update to lua 5.4 (#1174)
* update to lua 5.4.0-rc1 * remove LUA_ERRGCMM * use age bits for shared * remove unused lbitlib.c * use luaV_fastget * fix #1174 * suspend函数tailcall优化 * 防止没有session导致未调用suspend * luaH_setint check shared (#1184) * set LUA_GCGEN by default * fix #1174 (#1186) checkshared in sweeplist * update to lua 5.4 rc2 * update to lua 5.4 rc4 * move skynet.profile into snlua * Use lua_sethook to interrupt tight loops * remove lua_checksig * critical condition for signals * update to lua 5.4 released * lua 5.4 bugfix * update lua bugfix * fix lua_sharestring (#1224) * update lua * update lua 5.4 * update README * add skynet.select * add test * test error & discard * yield session * request error has no error message * add timeout to skynet.select * bugfix * for lua 5.4 * new version * bugfix * bugfix * use if instead of while * make local * yield in select for * update lua 5.4.1 * change lua version (#1245) Co-authored-by: xiaojin <xiaojin@onemt.com.cn> * update lua version number Co-authored-by: hong <hongling0@gmail.com> Co-authored-by: hong <hongling-0@qq.com> Co-authored-by: 风---自由 <996442717qqcom@gmail.com> Co-authored-by: xiaojin <xiaojin@onemt.com.cn>
This commit is contained in:
94
test/testselect.lua
Normal file
94
test/testselect.lua
Normal file
@@ -0,0 +1,94 @@
|
||||
local skynet = require "skynet"
|
||||
|
||||
local mode = ...
|
||||
|
||||
if mode == "slave" then
|
||||
|
||||
local COMMAND = {}
|
||||
|
||||
function COMMAND.ping(ti, str)
|
||||
skynet.sleep(ti)
|
||||
return str
|
||||
end
|
||||
|
||||
function COMMAND.error()
|
||||
error "ERROR"
|
||||
end
|
||||
|
||||
function COMMAND.exit()
|
||||
skynet.exit()
|
||||
end
|
||||
|
||||
skynet.start(function()
|
||||
skynet.dispatch("lua", function(_,_, cmd, ...)
|
||||
skynet.ret(skynet.pack(COMMAND[cmd](...)))
|
||||
end)
|
||||
end)
|
||||
|
||||
else
|
||||
|
||||
local function info(fmt, ...)
|
||||
skynet.error(string.format(fmt, ...))
|
||||
end
|
||||
|
||||
skynet.start(function()
|
||||
local slave = skynet.newservice(SERVICE_NAME, "slave")
|
||||
|
||||
for req, resp in skynet.request
|
||||
{ slave, "lua", "ping", 6, "SLEEP 6" }
|
||||
{ slave, "lua", "ping", 5, "SLEEP 5" }
|
||||
{ slave, "lua", "ping", 4, "SLEEP 4" }
|
||||
{ slave, "lua", "ping", 3, "SLEEP 3" }
|
||||
{ slave, "lua", "ping", 2, "SLEEP 2" }
|
||||
{ slave, "lua", "ping", 1, "SLEEP 1" }
|
||||
:select() do
|
||||
info("RESP %s", resp[1])
|
||||
end
|
||||
|
||||
-- test timeout
|
||||
local reqs = skynet.request()
|
||||
|
||||
for i = 1, 10 do
|
||||
reqs:add { slave, "lua", "ping", i*10, "SLEEP " .. i, token = i }
|
||||
end
|
||||
|
||||
for req, resp in reqs:select(50) do
|
||||
info("RESP %s token<%s>", resp[1], req.token)
|
||||
end
|
||||
|
||||
-- test error
|
||||
|
||||
for req, resp in skynet.request
|
||||
{ slave, "lua", "error" }
|
||||
{ slave, "lua", "ping", 0, "PING" }
|
||||
: select() do
|
||||
if resp then
|
||||
info("Ping : %s", resp[1])
|
||||
else
|
||||
info("Error")
|
||||
end
|
||||
end
|
||||
|
||||
-- timeout call
|
||||
|
||||
local reqs = skynet.request { slave, "lua", "ping", 100 , "PING" }
|
||||
for req, resp in reqs:select(10) do
|
||||
info("%s", resp[1])
|
||||
end
|
||||
|
||||
info("Timeout : %s", reqs.timeout)
|
||||
|
||||
-- call in select
|
||||
for req, resp in skynet.request
|
||||
{ slave, "lua", "ping", 20, "CALL 20" }
|
||||
{ slave, "lua", "ping", 10, "CALL 10" }
|
||||
: select() do
|
||||
info("%s", skynet.call( slave, "lua", "ping", 0, "ping in " .. resp[1]) )
|
||||
skynet.sleep(50)
|
||||
end
|
||||
|
||||
skynet.send(slave, "lua", "exit")
|
||||
skynet.exit()
|
||||
end)
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user