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
|
--TEST--
AMQPConnection constructor with timeout parameter in credentials
--SKIPIF--
<?php
if (!extension_loaded("amqp")) print "skip AMQP extension is not loaded";
elseif (getenv("SKIP_ONLINE_TESTS")) die('skip online test and SKIP_ONLINE_TESTS is set');
elseif (getenv("SKIP_SLOW_TESTS")) die('skip slow test and SKIP_SLOW_TESTS is set');
?>
--FILE--
<?php
try {
$cnn = new AMQPConnection(array('connect_timeout' => -1.5));
} catch (AMQPConnectionException $e) {
echo $e->getMessage(), PHP_EOL;
}
$timeout = 10.5;
// resolve hostname to don't waste time on resolve inside library while resolve operations are not under timings limit (yet)
$credentials = array('host' => gethostbyname('google.com'), 'connect_timeout' => $timeout);
//$credentials = array('host' => 'google.com', 'connect_timeout' => $timeout);
$cnn = new AMQPConnection($credentials);
$start = microtime(true);
try {
$cnn->connect();
} catch (AMQPConnectionException $e) {
echo $e->getMessage(), PHP_EOL;
$end = microtime(true);
$error = $end - $start - $timeout;
$limit = abs(log10($timeout)); // empirical value
echo 'error: ', $error, PHP_EOL;
echo 'limit: ', $limit, PHP_EOL;
echo abs($error) <= $limit ? 'timings OK' : 'timings failed'; // error should be less than 5% of timeout value
}
?>
--EXPECTF--
Parameter 'connect_timeout' must be greater than or equal to zero.
Socket error: could not connect to host, request timed out
error: %f
limit: %f
timings OK
|