public function testTimeoutConnection()
{
if (PHP_OS == 'Linux') {
shell_exec('sudo iptables -A OUTPUT -p tcp -m tcp --sport 9042 -j DROP');
} else {
$this->markTestSkipped("Your OS " . PHP_OS . " can not run timeout tests, since they depend on iptables");
}
$start = time();
try {
$connection = new Cassandra\Database(['127.0.0.1:9042'], null, ['connect_timeout_ms' => 2500]);
$connection->connect();
} catch (Cassandra\Exception\ClusterException $e) {
$catched = true;
}
$this->assertEquals(true, $catched);
$timespan = time() - $start;
shell_exec('sudo iptables -D OUTPUT -p tcp -m tcp --sport 9042 -j DROP');
$this->assertLessThanOrEqual(3, $timespan);
$this->assertGreaterThanOrEqual(2, $timespan);
}