diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-07-26 05:17:37 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-07-26 05:17:37 +0000 |
| commit | 911e8d7e7f63e6e90814e82955bfaf26328afb19 (patch) | |
| tree | 575a916f4616a0f865bff9928faa9be67a8c867e /test | |
| parent | d914007507a6a4ad3489cca19652af403fef7074 (diff) | |
| download | luasocket-911e8d7e7f63e6e90814e82955bfaf26328afb19.tar.gz luasocket-911e8d7e7f63e6e90814e82955bfaf26328afb19.tar.bz2 luasocket-911e8d7e7f63e6e90814e82955bfaf26328afb19.zip | |
Beta2 is out! Total timeout works on Windows.
Diffstat (limited to 'test')
| -rw-r--r-- | test/httptest.lua | 19 | ||||
| -rw-r--r-- | test/testclnt.lua | 39 |
2 files changed, 31 insertions, 27 deletions
diff --git a/test/httptest.lua b/test/httptest.lua index 31e8212..ce7a93b 100644 --- a/test/httptest.lua +++ b/test/httptest.lua | |||
| @@ -116,6 +116,16 @@ ignore = { | |||
| 116 | check_request(request, expect, ignore) | 116 | check_request(request, expect, ignore) |
| 117 | 117 | ||
| 118 | ------------------------------------------------------------------------ | 118 | ------------------------------------------------------------------------ |
| 119 | io.write("testing invalid url: ") | ||
| 120 | local c, e = socket.connect("", 80) | ||
| 121 | local r, re = http.request{url = host .. prefix} | ||
| 122 | assert(r == nil and e == re) | ||
| 123 | r, re = http.request(host .. prefix) | ||
| 124 | assert(r == nil and e == re, tostring(r) ..", " .. tostring(re) .. | ||
| 125 | " vs " .. tostring(e)) | ||
| 126 | print("ok") | ||
| 127 | |||
| 128 | ------------------------------------------------------------------------ | ||
| 119 | io.write("testing post method: ") | 129 | io.write("testing post method: ") |
| 120 | -- wanted to test chunked post, but apache doesn't support it... | 130 | -- wanted to test chunked post, but apache doesn't support it... |
| 121 | request = { | 131 | request = { |
| @@ -407,15 +417,6 @@ assert(r == nil and e == re) | |||
| 407 | print("ok") | 417 | print("ok") |
| 408 | 418 | ||
| 409 | ------------------------------------------------------------------------ | 419 | ------------------------------------------------------------------------ |
| 410 | io.write("testing invalid url: ") | ||
| 411 | local c, e = socket.connect("", 80) | ||
| 412 | local r, re = http.request{url = host .. prefix} | ||
| 413 | assert(r == nil and e == re) | ||
| 414 | r, re = http.request(host .. prefix) | ||
| 415 | assert(r == nil and e == re) | ||
| 416 | print("ok") | ||
| 417 | |||
| 418 | ------------------------------------------------------------------------ | ||
| 419 | print("passed all tests") | 420 | print("passed all tests") |
| 420 | os.remove("err") | 421 | os.remove("err") |
| 421 | 422 | ||
diff --git a/test/testclnt.lua b/test/testclnt.lua index 356350a..f838533 100644 --- a/test/testclnt.lua +++ b/test/testclnt.lua | |||
| @@ -461,6 +461,7 @@ end | |||
| 461 | ------------------------------------------------------------------------ | 461 | ------------------------------------------------------------------------ |
| 462 | function test_nonblocking(size) | 462 | function test_nonblocking(size) |
| 463 | reconnect() | 463 | reconnect() |
| 464 | print("Testing " .. 2*size .. " bytes") | ||
| 464 | remote(string.format([[ | 465 | remote(string.format([[ |
| 465 | data:send(string.rep("a", %d)) | 466 | data:send(string.rep("a", %d)) |
| 466 | socket.sleep(0.5) | 467 | socket.sleep(0.5) |
| @@ -471,7 +472,9 @@ remote(string.format([[ | |||
| 471 | local str | 472 | local str |
| 472 | data:settimeout(0) | 473 | data:settimeout(0) |
| 473 | while 1 do | 474 | while 1 do |
| 474 | str, err, part = data:receive(2*size - string.len(part), part) | 475 | local needed = 2*size - string.len(part) |
| 476 | assert(needed > 0, "weird") | ||
| 477 | str, err, part = data:receive(needed, part) | ||
| 475 | if err ~= "timeout" then break end | 478 | if err ~= "timeout" then break end |
| 476 | end | 479 | end |
| 477 | assert(str == (string.rep("a", size) .. string.rep("b", size))) | 480 | assert(str == (string.rep("a", size) .. string.rep("b", size))) |
| @@ -480,9 +483,7 @@ remote(string.format([[ | |||
| 480 | str = data:receive(%d) | 483 | str = data:receive(%d) |
| 481 | socket.sleep(0.5) | 484 | socket.sleep(0.5) |
| 482 | str = data:receive(%d, str) | 485 | str = data:receive(%d, str) |
| 483 | str = data:receive("*l", str) | ||
| 484 | data:send(str) | 486 | data:send(str) |
| 485 | data:send("\n") | ||
| 486 | ]], size, size)) | 487 | ]], size, size)) |
| 487 | data:settimeout(0) | 488 | data:settimeout(0) |
| 488 | local sofar = 1 | 489 | local sofar = 1 |
| @@ -493,25 +494,12 @@ remote(string.format([[ | |||
| 493 | end | 494 | end |
| 494 | data:send("\n") | 495 | data:send("\n") |
| 495 | data:settimeout(-1) | 496 | data:settimeout(-1) |
| 496 | local back = data:receive() | 497 | local back = data:receive(2*size) |
| 497 | assert(back == str) | 498 | assert(back == str, "'" .. back .. "' vs '" .. str .. "'") |
| 498 | print("ok") | 499 | print("ok") |
| 499 | end | 500 | end |
| 500 | 501 | ||
| 501 | |||
| 502 | ------------------------------------------------------------------------ | 502 | ------------------------------------------------------------------------ |
| 503 | test("non-blocking transfer") | ||
| 504 | test_nonblocking(1) | ||
| 505 | test_nonblocking(17) | ||
| 506 | test_nonblocking(200) | ||
| 507 | test_nonblocking(4091) | ||
| 508 | test_nonblocking(80199) | ||
| 509 | test_nonblocking(8000000) | ||
| 510 | test_nonblocking(80199) | ||
| 511 | test_nonblocking(4091) | ||
| 512 | test_nonblocking(200) | ||
| 513 | test_nonblocking(17) | ||
| 514 | test_nonblocking(1) | ||
| 515 | 503 | ||
| 516 | test("method registration") | 504 | test("method registration") |
| 517 | test_methods(socket.tcp(), { | 505 | test_methods(socket.tcp(), { |
| @@ -524,6 +512,7 @@ test_methods(socket.tcp(), { | |||
| 524 | "getpeername", | 512 | "getpeername", |
| 525 | "getsockname", | 513 | "getsockname", |
| 526 | "getstats", | 514 | "getstats", |
| 515 | "setstats", | ||
| 527 | "listen", | 516 | "listen", |
| 528 | "receive", | 517 | "receive", |
| 529 | "send", | 518 | "send", |
| @@ -628,6 +617,20 @@ test_raw(200) | |||
| 628 | test_raw(17) | 617 | test_raw(17) |
| 629 | test_raw(1) | 618 | test_raw(1) |
| 630 | 619 | ||
| 620 | test("non-blocking transfer") | ||
| 621 | test_nonblocking(1) | ||
| 622 | test_nonblocking(17) | ||
| 623 | test_nonblocking(200) | ||
| 624 | test_nonblocking(4091) | ||
| 625 | test_nonblocking(80199) | ||
| 626 | test_nonblocking(8000000) | ||
| 627 | test_nonblocking(80199) | ||
| 628 | test_nonblocking(4091) | ||
| 629 | test_nonblocking(200) | ||
| 630 | test_nonblocking(17) | ||
| 631 | test_nonblocking(1) | ||
| 632 | |||
| 633 | |||
| 631 | test("total timeout on send") | 634 | test("total timeout on send") |
| 632 | test_totaltimeoutsend(800091, 1, 3) | 635 | test_totaltimeoutsend(800091, 1, 3) |
| 633 | test_totaltimeoutsend(800091, 2, 3) | 636 | test_totaltimeoutsend(800091, 2, 3) |
