diff options
author | Caleb Maclennan <caleb@alerque.com> | 2023-11-10 09:12:04 +0300 |
---|---|---|
committer | Caleb Maclennan <caleb@alerque.com> | 2023-11-10 09:12:04 +0300 |
commit | 5c4fc93d5f4137bf4c22ddf1a048c907a4a26727 (patch) | |
tree | a9a68e1f6a9c3bfe2b64fa1c3a4098865b7d3b5d /test/utestclnt.lua | |
parent | ccef3bc4e2aa6ee5b997a80aabb58f4ff0b0e98f (diff) | |
parent | 43a97b7f0053313b43906371dbdc226271e6c8ab (diff) | |
download | luasocket-hjelmeland-patch-1.tar.gz luasocket-hjelmeland-patch-1.tar.bz2 luasocket-hjelmeland-patch-1.zip |
Merge branch 'master' into hjelmeland-patch-1hjelmeland-patch-1
Diffstat (limited to 'test/utestclnt.lua')
-rw-r--r-- | test/utestclnt.lua | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/test/utestclnt.lua b/test/utestclnt.lua index 34a0718..7f10643 100644 --- a/test/utestclnt.lua +++ b/test/utestclnt.lua | |||
@@ -54,30 +54,30 @@ function check_timeout(tm, sl, elapsed, err, opp, mode, alldone) | |||
54 | if not err then warn("must be buffered") | 54 | if not err then warn("must be buffered") |
55 | elseif err == "timeout" then pass("proper timeout") | 55 | elseif err == "timeout" then pass("proper timeout") |
56 | else fail("unexpected error '%s'", err) end | 56 | else fail("unexpected error '%s'", err) end |
57 | else | 57 | else |
58 | if err ~= "timeout" then fail("should have timed out") | 58 | if err ~= "timeout" then fail("should have timed out") |
59 | else pass("proper timeout") end | 59 | else pass("proper timeout") end |
60 | end | 60 | end |
61 | else | 61 | else |
62 | if mode == "total" then | 62 | if mode == "total" then |
63 | if elapsed > tm then | 63 | if elapsed > tm then |
64 | if err ~= "timeout" then fail("should have timed out") | 64 | if err ~= "timeout" then fail("should have timed out") |
65 | else pass("proper timeout") end | 65 | else pass("proper timeout") end |
66 | elseif elapsed < tm then | 66 | elseif elapsed < tm then |
67 | if err then fail(err) | 67 | if err then fail(err) |
68 | else pass("ok") end | 68 | else pass("ok") end |
69 | else | 69 | else |
70 | if alldone then | 70 | if alldone then |
71 | if err then fail("unexpected error '%s'", err) | 71 | if err then fail("unexpected error '%s'", err) |
72 | else pass("ok") end | 72 | else pass("ok") end |
73 | else | 73 | else |
74 | if err ~= "timeout" then fail(err) | 74 | if err ~= "timeout" then fail(err) |
75 | else pass("proper timeoutk") end | 75 | else pass("proper timeoutk") end |
76 | end | 76 | end |
77 | end | 77 | end |
78 | else | 78 | else |
79 | if err then fail(err) | 79 | if err then fail(err) |
80 | else pass("ok") end | 80 | else pass("ok") end |
81 | end | 81 | end |
82 | end | 82 | end |
83 | end | 83 | end |
@@ -104,7 +104,7 @@ function reconnect() | |||
104 | print("done " .. i) | 104 | print("done " .. i) |
105 | ]] | 105 | ]] |
106 | data, err = uconnect(host, port) | 106 | data, err = uconnect(host, port) |
107 | if not data then fail(err) | 107 | if not data then fail(err) |
108 | else pass("connected!") end | 108 | else pass("connected!") end |
109 | end | 109 | end |
110 | 110 | ||
@@ -116,8 +116,8 @@ else pass("connected!") end | |||
116 | ------------------------------------------------------------------------ | 116 | ------------------------------------------------------------------------ |
117 | function test_methods(sock, methods) | 117 | function test_methods(sock, methods) |
118 | for _, v in pairs(methods) do | 118 | for _, v in pairs(methods) do |
119 | if type(sock[v]) ~= "function" then | 119 | if type(sock[v]) ~= "function" then |
120 | fail(sock.class .. " method '" .. v .. "' not registered") | 120 | fail(sock.class .. " method '" .. v .. "' not registered") |
121 | end | 121 | end |
122 | end | 122 | end |
123 | pass(sock.class .. " methods are ok") | 123 | pass(sock.class .. " methods are ok") |
@@ -132,7 +132,7 @@ function test_mixed(len) | |||
132 | local p3 = "raw " .. string.rep("z", inter) .. "bytes" | 132 | local p3 = "raw " .. string.rep("z", inter) .. "bytes" |
133 | local p4 = "end" .. string.rep("w", inter) .. "bytes" | 133 | local p4 = "end" .. string.rep("w", inter) .. "bytes" |
134 | local bp1, bp2, bp3, bp4 | 134 | local bp1, bp2, bp3, bp4 |
135 | remote (string.format("str = data:receive(%d)", | 135 | remote (string.format("str = data:receive(%d)", |
136 | string.len(p1)+string.len(p2)+string.len(p3)+string.len(p4))) | 136 | string.len(p1)+string.len(p2)+string.len(p3)+string.len(p4))) |
137 | sent, err = data:send(p1..p2..p3..p4) | 137 | sent, err = data:send(p1..p2..p3..p4) |
138 | if err then fail(err) end | 138 | if err then fail(err) end |
@@ -172,7 +172,7 @@ function test_rawline(len) | |||
172 | reconnect() | 172 | reconnect() |
173 | local str, str10, back, err | 173 | local str, str10, back, err |
174 | str = string.rep(string.char(47), math.mod(len, 10)) | 174 | str = string.rep(string.char(47), math.mod(len, 10)) |
175 | str10 = string.rep(string.char(120,21,77,4,5,0,7,36,44,100), | 175 | str10 = string.rep(string.char(120,21,77,4,5,0,7,36,44,100), |
176 | math.floor(len/10)) | 176 | math.floor(len/10)) |
177 | str = str .. str10 | 177 | str = str .. str10 |
178 | remote "str = data:receive()" | 178 | remote "str = data:receive()" |
@@ -221,7 +221,7 @@ function test_totaltimeoutreceive(len, tm, sl) | |||
221 | data:settimeout(tm, "total") | 221 | data:settimeout(tm, "total") |
222 | local t = socket.gettime() | 222 | local t = socket.gettime() |
223 | str, err, partial, elapsed = data:receive(2*len) | 223 | str, err, partial, elapsed = data:receive(2*len) |
224 | check_timeout(tm, sl, elapsed, err, "receive", "total", | 224 | check_timeout(tm, sl, elapsed, err, "receive", "total", |
225 | string.len(str or partial) == 2*len) | 225 | string.len(str or partial) == 2*len) |
226 | end | 226 | end |
227 | 227 | ||
@@ -241,7 +241,7 @@ function test_totaltimeoutsend(len, tm, sl) | |||
241 | data:settimeout(tm, "total") | 241 | data:settimeout(tm, "total") |
242 | str = string.rep("a", 2*len) | 242 | str = string.rep("a", 2*len) |
243 | total, err, partial, elapsed = data:send(str) | 243 | total, err, partial, elapsed = data:send(str) |
244 | check_timeout(tm, sl, elapsed, err, "send", "total", | 244 | check_timeout(tm, sl, elapsed, err, "send", "total", |
245 | total == 2*len) | 245 | total == 2*len) |
246 | end | 246 | end |
247 | 247 | ||
@@ -261,7 +261,7 @@ function test_blockingtimeoutreceive(len, tm, sl) | |||
261 | ]], 2*tm, len, sl, sl)) | 261 | ]], 2*tm, len, sl, sl)) |
262 | data:settimeout(tm) | 262 | data:settimeout(tm) |
263 | str, err, partial, elapsed = data:receive(2*len) | 263 | str, err, partial, elapsed = data:receive(2*len) |
264 | check_timeout(tm, sl, elapsed, err, "receive", "blocking", | 264 | check_timeout(tm, sl, elapsed, err, "receive", "blocking", |
265 | string.len(str or partial) == 2*len) | 265 | string.len(str or partial) == 2*len) |
266 | end | 266 | end |
267 | 267 | ||
@@ -294,10 +294,10 @@ function empty_connect() | |||
294 | data = server:accept() | 294 | data = server:accept() |
295 | ]] | 295 | ]] |
296 | data, err = socket.connect("", port) | 296 | data, err = socket.connect("", port) |
297 | if not data then | 297 | if not data then |
298 | pass("ok") | 298 | pass("ok") |
299 | data = socket.connect(host, port) | 299 | data = socket.connect(host, port) |
300 | else | 300 | else |
301 | pass("gethostbyname returns localhost on empty string...") | 301 | pass("gethostbyname returns localhost on empty string...") |
302 | end | 302 | end |
303 | end | 303 | end |
@@ -331,7 +331,7 @@ function test_closed() | |||
331 | data:close() | 331 | data:close() |
332 | data = nil | 332 | data = nil |
333 | ]], str)) | 333 | ]], str)) |
334 | -- try to get a line | 334 | -- try to get a line |
335 | back, err, partial = data:receive() | 335 | back, err, partial = data:receive() |
336 | if not err then fail("should have gotten 'closed'.") | 336 | if not err then fail("should have gotten 'closed'.") |
337 | elseif err ~= "closed" then fail("got '"..err.."' instead of 'closed'.") | 337 | elseif err ~= "closed" then fail("got '"..err.."' instead of 'closed'.") |
@@ -344,25 +344,25 @@ function test_closed() | |||
344 | data = nil | 344 | data = nil |
345 | ]] | 345 | ]] |
346 | total, err, partial = data:send(string.rep("ugauga", 100000)) | 346 | total, err, partial = data:send(string.rep("ugauga", 100000)) |
347 | if not err then | 347 | if not err then |
348 | pass("failed: output buffer is at least %d bytes long!", total) | 348 | pass("failed: output buffer is at least %d bytes long!", total) |
349 | elseif err ~= "closed" then | 349 | elseif err ~= "closed" then |
350 | fail("got '"..err.."' instead of 'closed'.") | 350 | fail("got '"..err.."' instead of 'closed'.") |
351 | else | 351 | else |
352 | pass("graceful 'closed' received after %d bytes were sent", partial) | 352 | pass("graceful 'closed' received after %d bytes were sent", partial) |
353 | end | 353 | end |
354 | end | 354 | end |
355 | 355 | ||
356 | ------------------------------------------------------------------------ | 356 | ------------------------------------------------------------------------ |
357 | function test_selectbugs() | 357 | function test_selectbugs() |
358 | local r, s, e = socket.select(nil, nil, 0.1) | 358 | local r, s, e = socket.select(nil, nil, 0.1) |
359 | assert(type(r) == "table" and type(s) == "table" and | 359 | assert(type(r) == "table" and type(s) == "table" and |
360 | (e == "timeout" or e == "error")) | 360 | (e == "timeout" or e == "error")) |
361 | pass("both nil: ok") | 361 | pass("both nil: ok") |
362 | local udp = socket.udp() | 362 | local udp = socket.udp() |
363 | udp:close() | 363 | udp:close() |
364 | r, s, e = socket.select({ udp }, { udp }, 0.1) | 364 | r, s, e = socket.select({ udp }, { udp }, 0.1) |
365 | assert(type(r) == "table" and type(s) == "table" and | 365 | assert(type(r) == "table" and type(s) == "table" and |
366 | (e == "timeout" or e == "error")) | 366 | (e == "timeout" or e == "error")) |
367 | pass("closed sockets: ok") | 367 | pass("closed sockets: ok") |
368 | e = pcall(socket.select, "wrong", 1, 0.1) | 368 | e = pcall(socket.select, "wrong", 1, 0.1) |
@@ -380,7 +380,7 @@ function accept_timeout() | |||
380 | local t = socket.gettime() | 380 | local t = socket.gettime() |
381 | s:settimeout(1) | 381 | s:settimeout(1) |
382 | local c, e = s:accept() | 382 | local c, e = s:accept() |
383 | assert(not c, "should not accept") | 383 | assert(not c, "should not accept") |
384 | assert(e == "timeout", string.format("wrong error message (%s)", e)) | 384 | assert(e == "timeout", string.format("wrong error message (%s)", e)) |
385 | t = socket.gettime() - t | 385 | t = socket.gettime() - t |
386 | assert(t < 2, string.format("took to long to give up (%gs)", t)) | 386 | assert(t < 2, string.format("took to long to give up (%gs)", t)) |
@@ -398,9 +398,9 @@ function connect_timeout() | |||
398 | local t = socket.gettime() | 398 | local t = socket.gettime() |
399 | local r, e = c:connect("127.0.0.2", 80) | 399 | local r, e = c:connect("127.0.0.2", 80) |
400 | assert(not r, "should not connect") | 400 | assert(not r, "should not connect") |
401 | assert(socket.gettime() - t < 2, "took too long to give up.") | 401 | assert(socket.gettime() - t < 2, "took too long to give up.") |
402 | c:close() | 402 | c:close() |
403 | print("ok") | 403 | print("ok") |
404 | end | 404 | end |
405 | 405 | ||
406 | ------------------------------------------------------------------------ | 406 | ------------------------------------------------------------------------ |
@@ -463,9 +463,9 @@ function getstats_test() | |||
463 | data:receive(c) | 463 | data:receive(c) |
464 | t = t + c | 464 | t = t + c |
465 | local r, s, a = data:getstats() | 465 | local r, s, a = data:getstats() |
466 | assert(r == t, "received count failed" .. tostring(r) | 466 | assert(r == t, "received count failed" .. tostring(r) |
467 | .. "/" .. tostring(t)) | 467 | .. "/" .. tostring(t)) |
468 | assert(s == t, "sent count failed" .. tostring(s) | 468 | assert(s == t, "sent count failed" .. tostring(s) |
469 | .. "/" .. tostring(t)) | 469 | .. "/" .. tostring(t)) |
470 | end | 470 | end |
471 | print("ok") | 471 | print("ok") |
@@ -473,7 +473,7 @@ end | |||
473 | 473 | ||
474 | 474 | ||
475 | ------------------------------------------------------------------------ | 475 | ------------------------------------------------------------------------ |
476 | function test_nonblocking(size) | 476 | function test_nonblocking(size) |
477 | reconnect() | 477 | reconnect() |
478 | print("Testing " .. 2*size .. " bytes") | 478 | print("Testing " .. 2*size .. " bytes") |
479 | remote(string.format([[ | 479 | remote(string.format([[ |