2001-03-12 20:40:29 +01:00
|
|
|
HOST = HOST or "localhost"
|
2002-07-08 23:56:01 +02:00
|
|
|
PORT = PORT or "8080"
|
2001-01-25 22:59:59 +01:00
|
|
|
|
2002-07-08 23:56:01 +02:00
|
|
|
function pass(...)
|
2002-12-03 08:20:34 +01:00
|
|
|
local s = string.format(unpack(arg))
|
|
|
|
io.write(s, "\n")
|
2001-01-25 22:59:59 +01:00
|
|
|
end
|
|
|
|
|
2002-07-08 23:56:01 +02:00
|
|
|
function fail(...)
|
2002-12-03 08:20:34 +01:00
|
|
|
local s = string.format(unpack(arg))
|
|
|
|
io.write("ERROR: ", s, "!\n")
|
|
|
|
os.exit()
|
2001-01-25 22:59:59 +01:00
|
|
|
end
|
|
|
|
|
2002-07-08 23:56:01 +02:00
|
|
|
function warn(...)
|
2002-12-03 08:20:34 +01:00
|
|
|
local s = format(unpack(arg))
|
|
|
|
io.write("WARNING: ", s, "\n")
|
2001-01-25 22:59:59 +01:00
|
|
|
end
|
|
|
|
|
2002-07-08 23:56:01 +02:00
|
|
|
function remote(...)
|
2002-12-03 08:20:34 +01:00
|
|
|
local s = string.format(unpack(arg))
|
|
|
|
s = string.gsub(s, "\n", ";")
|
|
|
|
s = string.gsub(s, "%s+", " ")
|
|
|
|
s = string.gsub(s, "^%s*", "")
|
2002-07-08 23:56:01 +02:00
|
|
|
control:send(s, "\n")
|
|
|
|
control:receive()
|
2001-01-25 22:59:59 +01:00
|
|
|
end
|
|
|
|
|
2002-07-08 23:56:01 +02:00
|
|
|
function test(test)
|
2002-12-03 08:20:34 +01:00
|
|
|
io.write("----------------------------------------------\n",
|
2002-07-08 23:56:01 +02:00
|
|
|
"testing: ", test, "\n",
|
|
|
|
"----------------------------------------------\n")
|
2001-03-07 23:38:54 +01:00
|
|
|
end
|
|
|
|
|
2002-07-08 23:56:01 +02:00
|
|
|
function check_timeout(tm, sl, elapsed, err, opp, mode, alldone)
|
|
|
|
if tm < sl then
|
|
|
|
if opp == "send" then
|
|
|
|
if not err then warn("must be buffered")
|
|
|
|
elseif err == "timeout" then pass("proper timeout")
|
|
|
|
else fail("unexpected error '%s'", err) end
|
|
|
|
else
|
|
|
|
if err ~= "timeout" then fail("should have timed out")
|
|
|
|
else pass("proper timeout") end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if mode == "return" then
|
|
|
|
if elapsed > tm then
|
|
|
|
if err ~= "timeout" then fail("should have timed out")
|
|
|
|
else pass("proper timeout") end
|
|
|
|
elseif elapsed < tm then
|
|
|
|
if err then fail(err)
|
|
|
|
else pass("ok") end
|
|
|
|
else
|
|
|
|
if alldone then
|
|
|
|
if err then fail("unexpected error '%s'", err)
|
|
|
|
else pass("ok") end
|
|
|
|
else
|
|
|
|
if err ~= "timeout" then fail(err)
|
|
|
|
else pass("proper timeoutk") end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if err then fail(err)
|
|
|
|
else pass("ok") end
|
|
|
|
end
|
|
|
|
end
|
2001-01-25 22:59:59 +01:00
|
|
|
end
|
|
|
|
|
2002-12-03 08:20:34 +01:00
|
|
|
io.write("----------------------------------------------\n",
|
2002-07-08 23:56:01 +02:00
|
|
|
"LuaSocket Test Procedures\n",
|
|
|
|
"----------------------------------------------\n")
|
2001-01-25 22:59:59 +01:00
|
|
|
|
2002-12-03 08:20:34 +01:00
|
|
|
if not socket._time or not socket._sleep then
|
|
|
|
fail("not compiled with _DEBUG")
|
|
|
|
end
|
2001-01-25 22:59:59 +01:00
|
|
|
|
2002-12-03 08:20:34 +01:00
|
|
|
start = socket._time()
|
2001-01-25 22:59:59 +01:00
|
|
|
|
2002-07-08 23:56:01 +02:00
|
|
|
function tcpreconnect()
|
2002-12-03 08:20:34 +01:00
|
|
|
io.write("attempting data connection... ")
|
2002-07-08 23:56:01 +02:00
|
|
|
if data then data:close() end
|
|
|
|
remote [[
|
|
|
|
if data then data:close() data = nil end
|
|
|
|
data = server:accept()
|
|
|
|
]]
|
2002-12-03 08:20:34 +01:00
|
|
|
data, err = socket.connect(HOST, PORT)
|
|
|
|
if not data then fail(err)
|
2002-07-08 23:56:01 +02:00
|
|
|
else pass("connected!") end
|
2001-01-25 22:59:59 +01:00
|
|
|
end
|
2002-07-08 23:56:01 +02:00
|
|
|
reconnect = tcpreconnect
|
2001-01-25 22:59:59 +01:00
|
|
|
|
2002-07-08 23:56:01 +02:00
|
|
|
pass("attempting control connection...")
|
2002-12-03 08:20:34 +01:00
|
|
|
control, err = socket.connect(HOST, PORT)
|
|
|
|
if err then fail(err)
|
2002-07-08 23:56:01 +02:00
|
|
|
else pass("connected!") end
|
2001-01-25 22:59:59 +01:00
|
|
|
|
2002-07-08 23:56:01 +02:00
|
|
|
------------------------------------------------------------------------
|
|
|
|
test("bugs")
|
2001-01-25 22:59:59 +01:00
|
|
|
|
2002-12-03 08:20:34 +01:00
|
|
|
io.write("empty host connect: ")
|
2002-07-08 23:56:01 +02:00
|
|
|
function empty_connect()
|
|
|
|
if data then data:close() data = nil end
|
|
|
|
remote [[
|
|
|
|
if data then data:close() data = nil end
|
|
|
|
data = server:accept()
|
|
|
|
]]
|
2002-12-03 08:20:34 +01:00
|
|
|
data, err = socket.connect("", PORT)
|
2002-07-08 23:56:01 +02:00
|
|
|
if not data then
|
|
|
|
pass("ok")
|
2002-12-03 08:20:34 +01:00
|
|
|
data = socket.connect(HOST, PORT)
|
2002-07-08 23:56:01 +02:00
|
|
|
else fail("should not have connected!") end
|
2001-03-07 23:38:54 +01:00
|
|
|
end
|
|
|
|
|
2002-07-08 23:56:01 +02:00
|
|
|
empty_connect()
|
|
|
|
|
2002-12-03 08:20:34 +01:00
|
|
|
io.write("active close: ")
|
|
|
|
function active_close()
|
|
|
|
reconnect()
|
|
|
|
if socket._isclosed(data) then fail("should not be closed") end
|
|
|
|
data:close()
|
|
|
|
if not socket._isclosed(data) then fail("should be closed") end
|
|
|
|
data = nil
|
|
|
|
local udp = socket.udp()
|
|
|
|
if socket._isclosed(udp) then fail("should not be closed") end
|
|
|
|
udp:close()
|
|
|
|
if not socket._isclosed(udp) then fail("should be closed") end
|
|
|
|
pass("ok")
|
|
|
|
end
|
|
|
|
|
|
|
|
active_close()
|
|
|
|
|
2002-07-08 23:56:01 +02:00
|
|
|
------------------------------------------------------------------------
|
|
|
|
test("method registration")
|
|
|
|
|
|
|
|
function test_methods(sock, methods)
|
|
|
|
for _, v in methods do
|
|
|
|
if type(sock[v]) ~= "function" then
|
|
|
|
fail(type(sock) .. " method " .. v .. "not registered")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
pass(type(sock) .. " methods are ok")
|
2001-01-25 22:59:59 +01:00
|
|
|
end
|
|
|
|
|
2002-07-08 23:56:01 +02:00
|
|
|
test_methods(control, {
|
|
|
|
"close",
|
|
|
|
"timeout",
|
|
|
|
"send",
|
|
|
|
"receive",
|
|
|
|
"getpeername",
|
|
|
|
"getsockname"
|
|
|
|
})
|
|
|
|
|
|
|
|
if udpsocket then
|
2002-12-03 08:20:34 +01:00
|
|
|
test_methods(socket.udp(), {
|
2002-07-08 23:56:01 +02:00
|
|
|
"close",
|
|
|
|
"timeout",
|
|
|
|
"send",
|
|
|
|
"sendto",
|
|
|
|
"receive",
|
|
|
|
"receivefrom",
|
|
|
|
"getpeername",
|
|
|
|
"getsockname",
|
|
|
|
"setsockname",
|
|
|
|
"setpeername"
|
|
|
|
})
|
2001-06-09 00:42:01 +02:00
|
|
|
end
|
|
|
|
|
2002-12-03 08:20:34 +01:00
|
|
|
test_methods(socket.bind("*", 0), {
|
2002-07-08 23:56:01 +02:00
|
|
|
"close",
|
|
|
|
"timeout",
|
|
|
|
"accept"
|
|
|
|
})
|
2001-01-25 22:59:59 +01:00
|
|
|
|
2002-07-08 23:56:01 +02:00
|
|
|
------------------------------------------------------------------------
|
|
|
|
test("select function")
|
|
|
|
function test_selectbugs()
|
2002-12-03 08:20:34 +01:00
|
|
|
local r, s, e = socket.select(nil, nil, 0.1)
|
2002-07-08 23:56:01 +02:00
|
|
|
assert(type(r) == "table" and type(s) == "table" and e == "timeout")
|
|
|
|
pass("both nil: ok")
|
2002-12-03 08:20:34 +01:00
|
|
|
local udp = socket.udp()
|
2002-07-08 23:56:01 +02:00
|
|
|
udp:close()
|
2002-12-03 08:20:34 +01:00
|
|
|
r, s, e = socket.select({ udp }, { udp }, 0.1)
|
2002-07-08 23:56:01 +02:00
|
|
|
assert(type(r) == "table" and type(s) == "table" and e == "timeout")
|
|
|
|
pass("closed sockets: ok")
|
2002-12-03 08:20:34 +01:00
|
|
|
e = pcall(socket.select, "wrong", 1, 0.1)
|
|
|
|
assert(e == false)
|
|
|
|
e = pcall(socket.select, {}, 1, 0.1)
|
|
|
|
assert(e == false)
|
2002-07-08 23:56:01 +02:00
|
|
|
pass("invalid input: ok")
|
|
|
|
end
|
2001-01-25 22:59:59 +01:00
|
|
|
|
2002-07-08 23:56:01 +02:00
|
|
|
test_selectbugs()
|
2001-01-25 22:59:59 +01:00
|
|
|
|
2002-07-08 23:56:01 +02:00
|
|
|
------------------------------------------------------------------------
|
|
|
|
test("character line")
|
|
|
|
reconnect()
|
|
|
|
|
|
|
|
function test_asciiline(len)
|
|
|
|
local str, str10, back, err
|
2002-12-03 08:20:34 +01:00
|
|
|
str = string.rep("x", math.mod(len, 10))
|
|
|
|
str10 = string.rep("aZb.c#dAe?", math.floor(len/10))
|
2002-07-08 23:56:01 +02:00
|
|
|
str = str .. str10
|
|
|
|
pass(len .. " byte(s) line")
|
|
|
|
remote "str = data:receive()"
|
|
|
|
err = data:send(str, "\n")
|
|
|
|
if err then fail(err) end
|
|
|
|
remote "data:send(str, '\\n')"
|
|
|
|
back, err = data:receive()
|
|
|
|
if err then fail(err) end
|
|
|
|
if back == str then pass("lines match")
|
|
|
|
else fail("lines don't match") end
|
|
|
|
end
|
2001-03-07 23:38:54 +01:00
|
|
|
|
2001-01-25 22:59:59 +01:00
|
|
|
test_asciiline(1)
|
|
|
|
test_asciiline(17)
|
|
|
|
test_asciiline(200)
|
2002-07-08 23:56:01 +02:00
|
|
|
test_asciiline(4091)
|
|
|
|
test_asciiline(80199)
|
2001-01-25 22:59:59 +01:00
|
|
|
test_asciiline(800000)
|
|
|
|
|
2002-07-08 23:56:01 +02:00
|
|
|
------------------------------------------------------------------------
|
|
|
|
test("binary line")
|
|
|
|
reconnect()
|
|
|
|
|
|
|
|
function test_rawline(len)
|
|
|
|
local str, str10, back, err
|
2002-12-03 08:20:34 +01:00
|
|
|
str = string.rep(string.char(47), math.mod(len, 10))
|
|
|
|
str10 = string.rep(string.char(120,21,77,4,5,0,7,36,44,100),
|
|
|
|
math.floor(len/10))
|
2002-07-08 23:56:01 +02:00
|
|
|
str = str .. str10
|
|
|
|
pass(len .. " byte(s) line")
|
|
|
|
remote "str = data:receive()"
|
|
|
|
err = data:send(str, "\n")
|
|
|
|
if err then fail(err) end
|
|
|
|
remote "data:send(str, '\\n')"
|
|
|
|
back, err = data:receive()
|
|
|
|
if err then fail(err) end
|
|
|
|
if back == str then pass("lines match")
|
|
|
|
else fail("lines don't match") end
|
|
|
|
end
|
|
|
|
|
2001-01-25 22:59:59 +01:00
|
|
|
test_rawline(1)
|
|
|
|
test_rawline(17)
|
|
|
|
test_rawline(200)
|
2002-07-08 23:56:01 +02:00
|
|
|
test_rawline(4091)
|
|
|
|
test_rawline(80199)
|
2001-01-25 22:59:59 +01:00
|
|
|
test_rawline(800000)
|
2002-07-08 23:56:01 +02:00
|
|
|
test_rawline(80199)
|
|
|
|
test_rawline(4091)
|
|
|
|
test_rawline(200)
|
|
|
|
test_rawline(17)
|
|
|
|
test_rawline(1)
|
2001-01-25 22:59:59 +01:00
|
|
|
|
2002-07-08 23:56:01 +02:00
|
|
|
------------------------------------------------------------------------
|
|
|
|
test("raw transfer")
|
|
|
|
reconnect()
|
|
|
|
|
|
|
|
function test_raw(len)
|
2002-12-03 08:20:34 +01:00
|
|
|
local half = math.floor(len/2)
|
2002-07-08 23:56:01 +02:00
|
|
|
local s1, s2, back, err
|
2002-12-03 08:20:34 +01:00
|
|
|
s1 = string.rep("x", half)
|
|
|
|
s2 = string.rep("y", len-half)
|
2002-07-08 23:56:01 +02:00
|
|
|
pass(len .. " byte(s) block")
|
2002-12-03 08:20:34 +01:00
|
|
|
remote (string.format("str = data:receive(%d)", len))
|
2002-07-08 23:56:01 +02:00
|
|
|
err = data:send(s1)
|
|
|
|
if err then fail(err) end
|
|
|
|
err = data:send(s2)
|
|
|
|
if err then fail(err) end
|
|
|
|
remote "data:send(str)"
|
|
|
|
back, err = data:receive(len)
|
|
|
|
if err then fail(err) end
|
|
|
|
if back == s1..s2 then pass("blocks match")
|
|
|
|
else fail("blocks don't match") end
|
|
|
|
end
|
|
|
|
|
|
|
|
test_raw(1)
|
|
|
|
test_raw(17)
|
|
|
|
test_raw(200)
|
|
|
|
test_raw(4091)
|
|
|
|
test_raw(80199)
|
|
|
|
test_raw(800000)
|
|
|
|
test_raw(80199)
|
|
|
|
test_raw(4091)
|
|
|
|
test_raw(200)
|
|
|
|
test_raw(17)
|
|
|
|
test_raw(1)
|
|
|
|
------------------------------------------------------------------------
|
|
|
|
test("non-blocking transfer")
|
|
|
|
reconnect()
|
2001-01-25 22:59:59 +01:00
|
|
|
|
|
|
|
-- the value is not important, we only want
|
|
|
|
-- to test non-blockin I/O anyways
|
2001-03-06 21:16:17 +01:00
|
|
|
data:timeout(200)
|
2002-07-08 23:56:01 +02:00
|
|
|
test_raw(1)
|
|
|
|
test_raw(17)
|
|
|
|
test_raw(200)
|
|
|
|
test_raw(4091)
|
|
|
|
test_raw(80199)
|
|
|
|
test_raw(800000)
|
|
|
|
test_raw(80199)
|
|
|
|
test_raw(4091)
|
|
|
|
test_raw(200)
|
|
|
|
test_raw(17)
|
|
|
|
test_raw(1)
|
|
|
|
|
|
|
|
------------------------------------------------------------------------
|
|
|
|
test("mixed patterns")
|
|
|
|
reconnect()
|
|
|
|
|
|
|
|
function test_mixed(len)
|
2002-12-03 08:20:34 +01:00
|
|
|
local inter = math.floor(len/3)
|
|
|
|
local p1 = "unix " .. string.rep("x", inter) .. "line\n"
|
|
|
|
local p2 = "dos " .. string.rep("y", inter) .. "line\r\n"
|
|
|
|
local p3 = "raw " .. string.rep("z", inter) .. "bytes"
|
2002-07-08 23:56:01 +02:00
|
|
|
local bp1, bp2, bp3
|
|
|
|
pass(len .. " byte(s) patterns")
|
2002-12-03 08:20:34 +01:00
|
|
|
remote (string.format("str = data:receive(%d)",
|
|
|
|
string.len(p1)+string.len(p2)+string.len(p3)))
|
2002-07-08 23:56:01 +02:00
|
|
|
err = data:send(p1, p2, p3)
|
|
|
|
if err then fail(err) end
|
|
|
|
remote "data:send(str)"
|
2002-12-03 08:20:34 +01:00
|
|
|
bp1, bp2, bp3, err = data:receive("*lu", "*l", string.len(p3))
|
2002-07-08 23:56:01 +02:00
|
|
|
if err then fail(err) end
|
|
|
|
if bp1.."\n" == p1 and bp2.."\r\n" == p2 and bp3 == p3 then
|
|
|
|
pass("patterns match")
|
|
|
|
else fail("patterns don't match") end
|
|
|
|
end
|
|
|
|
|
|
|
|
test_mixed(1)
|
|
|
|
test_mixed(17)
|
|
|
|
test_mixed(200)
|
|
|
|
test_mixed(4091)
|
|
|
|
test_mixed(80199)
|
|
|
|
test_mixed(800000)
|
|
|
|
test_mixed(80199)
|
|
|
|
test_mixed(4091)
|
|
|
|
test_mixed(200)
|
|
|
|
test_mixed(17)
|
|
|
|
test_mixed(1)
|
|
|
|
|
|
|
|
------------------------------------------------------------------------
|
|
|
|
test("closed connection detection")
|
|
|
|
|
|
|
|
function test_closed()
|
|
|
|
local back, err
|
|
|
|
local str = 'little string'
|
|
|
|
reconnect()
|
|
|
|
pass("trying read detection")
|
2002-12-03 08:20:34 +01:00
|
|
|
remote (string.format ([[
|
2002-07-08 23:56:01 +02:00
|
|
|
data:send('%s')
|
|
|
|
data:close()
|
|
|
|
data = nil
|
|
|
|
]], str))
|
|
|
|
-- try to get a line
|
|
|
|
back, err = data:receive()
|
|
|
|
if not err then fail("shold have gotten 'closed'.")
|
|
|
|
elseif err ~= "closed" then fail("got '"..err.."' instead of 'closed'.")
|
|
|
|
elseif str ~= back then fail("didn't receive partial result.")
|
|
|
|
else pass("graceful 'closed' received") end
|
|
|
|
reconnect()
|
|
|
|
pass("trying write detection")
|
|
|
|
remote [[
|
|
|
|
data:close()
|
|
|
|
data = nil
|
|
|
|
]]
|
2002-12-03 08:20:34 +01:00
|
|
|
err, total = data:send(string.rep("ugauga", 100000))
|
2002-07-08 23:56:01 +02:00
|
|
|
if not err then
|
|
|
|
pass("failed: output buffer is at least %d bytes long!", total)
|
|
|
|
elseif err ~= "closed" then
|
|
|
|
fail("got '"..err.."' instead of 'closed'.")
|
|
|
|
else
|
|
|
|
pass("graceful 'closed' received after %d bytes were sent", total)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test_closed()
|
|
|
|
|
|
|
|
------------------------------------------------------------------------
|
|
|
|
test("return timeout on receive")
|
|
|
|
function test_blockingtimeoutreceive(len, tm, sl)
|
|
|
|
local str, err, total
|
|
|
|
reconnect()
|
|
|
|
pass("%d bytes, %ds return timeout, %ds pause", len, tm, sl)
|
2002-12-03 08:20:34 +01:00
|
|
|
remote (string.format ([[
|
2002-07-08 23:56:01 +02:00
|
|
|
data:timeout(%d)
|
2002-12-03 08:20:34 +01:00
|
|
|
str = string.rep('a', %d)
|
2002-07-08 23:56:01 +02:00
|
|
|
data:send(str)
|
|
|
|
print('server: sleeping for %ds')
|
2002-12-03 08:20:34 +01:00
|
|
|
socket._sleep(%d)
|
2002-07-08 23:56:01 +02:00
|
|
|
print('server: woke up')
|
|
|
|
data:send(str)
|
|
|
|
]], 2*tm, len, sl, sl))
|
|
|
|
data:timeout(tm, "return")
|
|
|
|
str, err, elapsed = data:receive(2*len)
|
|
|
|
check_timeout(tm, sl, elapsed, err, "receive", "return",
|
2002-12-03 08:20:34 +01:00
|
|
|
string.len(str) == 2*len)
|
2002-07-08 23:56:01 +02:00
|
|
|
end
|
|
|
|
test_blockingtimeoutreceive(800091, 1, 3)
|
|
|
|
test_blockingtimeoutreceive(800091, 2, 3)
|
|
|
|
test_blockingtimeoutreceive(800091, 3, 2)
|
|
|
|
test_blockingtimeoutreceive(800091, 3, 1)
|
|
|
|
|
|
|
|
------------------------------------------------------------------------
|
|
|
|
test("return timeout on send")
|
|
|
|
function test_returntimeoutsend(len, tm, sl)
|
|
|
|
local str, err, total
|
|
|
|
reconnect()
|
|
|
|
pass("%d bytes, %ds return timeout, %ds pause", len, tm, sl)
|
2002-12-03 08:20:34 +01:00
|
|
|
remote (string.format ([[
|
2002-07-08 23:56:01 +02:00
|
|
|
data:timeout(%d)
|
|
|
|
str = data:receive(%d)
|
|
|
|
print('server: sleeping for %ds')
|
2002-12-03 08:20:34 +01:00
|
|
|
socket._sleep(%d)
|
2002-07-08 23:56:01 +02:00
|
|
|
print('server: woke up')
|
|
|
|
str = data:receive(%d)
|
|
|
|
]], 2*tm, len, sl, sl, len))
|
|
|
|
data:timeout(tm, "return")
|
2002-12-03 08:20:34 +01:00
|
|
|
str = string.rep("a", 2*len)
|
2002-07-08 23:56:01 +02:00
|
|
|
err, total, elapsed = data:send(str)
|
|
|
|
check_timeout(tm, sl, elapsed, err, "send", "return",
|
|
|
|
total == 2*len)
|
|
|
|
end
|
|
|
|
test_returntimeoutsend(800091, 1, 3)
|
|
|
|
test_returntimeoutsend(800091, 2, 3)
|
|
|
|
test_returntimeoutsend(800091, 3, 2)
|
|
|
|
test_returntimeoutsend(800091, 3, 1)
|
|
|
|
|
|
|
|
|
|
|
|
------------------------------------------------------------------------
|
|
|
|
test("blocking timeout on receive")
|
|
|
|
function test_blockingtimeoutreceive(len, tm, sl)
|
|
|
|
local str, err, total
|
|
|
|
reconnect()
|
|
|
|
pass("%d bytes, %ds blocking timeout, %ds pause", len, tm, sl)
|
2002-12-03 08:20:34 +01:00
|
|
|
remote (string.format ([[
|
2002-07-08 23:56:01 +02:00
|
|
|
data:timeout(%d)
|
2002-12-03 08:20:34 +01:00
|
|
|
str = string.rep('a', %d)
|
2002-07-08 23:56:01 +02:00
|
|
|
data:send(str)
|
|
|
|
print('server: sleeping for %ds')
|
2002-12-03 08:20:34 +01:00
|
|
|
socket._sleep(%d)
|
2002-07-08 23:56:01 +02:00
|
|
|
print('server: woke up')
|
|
|
|
data:send(str)
|
|
|
|
]], 2*tm, len, sl, sl))
|
|
|
|
data:timeout(tm)
|
|
|
|
str, err, elapsed = data:receive(2*len)
|
|
|
|
check_timeout(tm, sl, elapsed, err, "receive", "blocking",
|
2002-12-03 08:20:34 +01:00
|
|
|
string.len(str) == 2*len)
|
2002-07-08 23:56:01 +02:00
|
|
|
end
|
|
|
|
test_blockingtimeoutreceive(800091, 1, 3)
|
|
|
|
test_blockingtimeoutreceive(800091, 2, 3)
|
|
|
|
test_blockingtimeoutreceive(800091, 3, 2)
|
|
|
|
test_blockingtimeoutreceive(800091, 3, 1)
|
|
|
|
|
|
|
|
|
|
|
|
------------------------------------------------------------------------
|
|
|
|
test("blocking timeout on send")
|
|
|
|
function test_blockingtimeoutsend(len, tm, sl)
|
|
|
|
local str, err, total
|
|
|
|
reconnect()
|
|
|
|
pass("%d bytes, %ds blocking timeout, %ds pause", len, tm, sl)
|
2002-12-03 08:20:34 +01:00
|
|
|
remote (string.format ([[
|
2002-07-08 23:56:01 +02:00
|
|
|
data:timeout(%d)
|
|
|
|
str = data:receive(%d)
|
|
|
|
print('server: sleeping for %ds')
|
2002-12-03 08:20:34 +01:00
|
|
|
socket._sleep(%d)
|
2002-07-08 23:56:01 +02:00
|
|
|
print('server: woke up')
|
|
|
|
str = data:receive(%d)
|
|
|
|
]], 2*tm, len, sl, sl, len))
|
|
|
|
data:timeout(tm)
|
2002-12-03 08:20:34 +01:00
|
|
|
str = string.rep("a", 2*len)
|
2002-07-08 23:56:01 +02:00
|
|
|
err, total, elapsed = data:send(str)
|
|
|
|
check_timeout(tm, sl, elapsed, err, "send", "blocking",
|
|
|
|
total == 2*len)
|
|
|
|
end
|
|
|
|
test_blockingtimeoutsend(800091, 1, 3)
|
|
|
|
test_blockingtimeoutsend(800091, 2, 3)
|
|
|
|
test_blockingtimeoutsend(800091, 3, 2)
|
|
|
|
test_blockingtimeoutsend(800091, 3, 1)
|
|
|
|
|
|
|
|
------------------------------------------------------------------------
|
2002-12-03 08:20:34 +01:00
|
|
|
test(string.format("done in %.2fs", socket._time() - start))
|