summaryrefslogtreecommitdiff
path: root/test/it_url_slow.t
blob: 00bbc2fe87106789f66889f83173956e58b646fb (plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/www/server/bin/php -qC
<?php

# slow tests for url.class

# TESTFLAGS SLOW

require 'it_url_server.php';

handle_server(
	is(
		it_url::get("http://$host/short_sleep"),
		"Testserver output after short sleep",
		'it_url::get() receives full output after short sleep'
	)
);

$start = microtime(true);
$res = is(
	it_url::get(['url' => "http://$host/long_sleep", 'timeout' => 4, 'retries' => 0, 'it_error' => false]),
	false,
	'it_url::get() fails after timeout seconds with no output'
);
$duration = microtime(true) - $start;
$res2 = ok(
	$duration >= 4 && $duration <= 6,
	'... and fails as soon as timeout is surpassed'
);
sleep(1); # wait for testserver
$output = server_output();
if (!$res || !$res2)
	diag($output);

handle_server(
	is(
		it_url::get("http://$host/slow_response"),
		implode('', it::map('"Testserver slow output $v\n"', range(0, 5))),
		'it_url::get() waits for slow response with continuous output'
	)
);

$start = microtime(true);
$res = ok(
	!it_url::get(['url' => "http://$host/slow_response", 'totaltimeout' => 5, 'retries' => 0, 'it_error' => false]),
	'it_url::get() fails for response slower than totaltimeout'
);
$res2 = is(
	intval(microtime(true) - $start), 5,
	'... and fails as soon as totaltimeout is surpassed'
);
sleep(1); # wait for testserver
$output = server_output();
if (!$res || !$res2)
	diag($output);

$start = microtime(true);
$res = ok(
	!it_url::get(['url' => "http://$host/slow_response", 'maxlength' => 10, 'retries' => 0, 'it_error' => false]),
	'it_url::get() fails for response larger than maxlength'
);
$res2 = is(
	intval(microtime(true) - $start), 1,
	'... and fails as soon as maxlength is surpassed'
);
sleep(1); # wait for testserver
$output = server_output();
if (!$res || !$res2)
	diag($output);

handle_server(
	ok(
		it_url::get(U("http://$host/repeat", ['string' => "abc", 'num' => 1024 * 1024])) == str_repeat("abc", 1024 * 1024),
		'it_url::get() handles large response'
	)
);


handle_server(
	ok(
		it_url::get(['url' => U("http://$host/repeat", ['string' => "abc", 'num' => 1024 * 32]), 'maxlength' => 1024 * 1024]) == str_repeat("abc", 1024 * 32),
		'it_url::get() handles large response with maxlength set'
	)
);

$start = microtime(true);
it_url::get_multi(['urls' => ['slow' => "http://$host/long_sleep", 'fast' => ['url' => 'http://search.ch/', 'handler' => function () {return true;}]]]);
ok(intval(microtime(true) - $start) < 4, 'get_multi with handler aborts after fast request');
$output = server_output();