1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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);
|