diff options
author | Nathan Gass | 2012-10-15 17:46:19 +0000 |
---|---|---|
committer | Nathan Gass | 2012-10-15 17:46:19 +0000 |
commit | 874e0c2a05d9ad38ee495301ca366b67d13d77dd (patch) | |
tree | 6891a9d494e7804c502aec1a90d2ac095204ebb8 | |
parent | ec2b0d1c3ad2b285adeea8bbb7e40878d82b4f98 (diff) | |
download | itools-874e0c2a05d9ad38ee495301ca366b67d13d77dd.tar.gz itools-874e0c2a05d9ad38ee495301ca366b67d13d77dd.tar.bz2 itools-874e0c2a05d9ad38ee495301ca366b67d13d77dd.zip |
add tests for it_url::get timeouts
-rw-r--r-- | tests/it_url.testserver.php | 17 | ||||
-rwxr-xr-x | tests/it_url_slow.t | 67 |
2 files changed, 84 insertions, 0 deletions
diff --git a/tests/it_url.testserver.php b/tests/it_url.testserver.php index 2d10052..22dc14b 100644 --- a/tests/it_url.testserver.php +++ b/tests/it_url.testserver.php @@ -34,6 +34,23 @@ switch ($_SERVER['PHP_SELF']) echo 'Testserver output after ' . $_REQUEST['type'] . ' redirect'; break; + case "/long_sleep": + sleep(6); + echo 'Testserver output after long sleep'; + break; + + case "/short_sleep": + sleep(4); + echo 'Testserver output after short sleep'; + break; + + case "/slow_response": + for ($i = 0; $i < 6; $i++) { + sleep(1); + echo "Testserver slow output $i\n"; + } + break; + default: fwrite($stderr, "Unknown path '$_SERVER[PHP_SELF]' not handled!\n"); } diff --git a/tests/it_url_slow.t b/tests/it_url_slow.t new file mode 100755 index 0000000..9474ef8 --- /dev/null +++ b/tests/it_url_slow.t @@ -0,0 +1,67 @@ +#!/www/server/bin/php -qC +<?php + +# slow tests for url.class + +# TESTFLAGS SLOW + +$server = proc_open( + 'php -S localhost:8000 ' . dirname($_SERVER['PHP_SELF']) . '/it_url.testserver.php', + array(0 => fopen('/dev/null', 'r'), 1 => fopen('/dev/null', 'w'), 2 => array('pipe', 'w')), + $pipes +); +usleep(100000); +stream_set_blocking($pipes[2], 0); +function server_output() { + $result = array(); + while (($result[] = trim(fgets($GLOBALS['pipes'][2])))) {}; + return array_filter($result); +} + +$res = is( + it_url::get('http://localhost:8000/short_sleep'), + "Testserver output after short sleep", + 'it_url::get() waits for 4 seconds', +); +$output = server_output(); +if (!$res) + diag($output); + +$start = microtime(true); +$res = ok( + !it_url::get(array('url' => 'http://localhost:8000/long_sleep', 'timeout' => 5, 'retries' => 0)), + 'it_url::get() fails after timeout seconds with no output', +); +$res2 = is( + floor(microtime(true) - $start), 5, + '... and fails as soon as timeout is surpassed', +); +sleep(1); # wait for testserver +$output = server_output(); +if (!$res || !$res2) + diag($output); + +$res = is( + it_url::get('http://localhost:8000/slow_response'), + join('', it::map('"Testserver slow output $v\n"', range(0, 5))), + 'it_url::get() waits for slow response with continuous output', +); +$output = server_output(); +if (!$res) + diag($output); + +$start = microtime(true); +$res = ok( + !it_url::get(array('url' => 'http://localhost:8000/slow_response', 'totaltimeout' => 5, 'retries' => 0)), + 'it_url::get() fails for response slower than totaltimeout', +); +$res2 = is( + floor(microtime(true) - $start), 5, + '... and fails as soon as totaltimeout is surpassed' +); +$output = server_output(); +if (!$res || !$res2) + diag($output); + +proc_terminate($server); + |