1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-22 04:43:12 +02:00

Merge pull request #668 from silvadanilo/avoid_infinite_loop

Avoid infinite loops when no data is written on a socket for a time
This commit is contained in:
Jordi Boggiano
2015-10-28 15:18:16 +00:00
2 changed files with 80 additions and 0 deletions

View File

@@ -70,6 +70,13 @@ class SocketHandlerTest extends TestCase
$this->assertEquals(10.25, $this->handler->getTimeout());
}
public function testSetWritingTimeout()
{
$this->createHandler('localhost:1234');
$this->handler->setWritingTimeout(10.25);
$this->assertEquals(10.25, $this->handler->getWritingTimeout());
}
public function testSetConnectionString()
{
$this->createHandler('tcp://localhost:9090');
@@ -235,6 +242,26 @@ class SocketHandlerTest extends TestCase
$this->assertTrue(is_resource($this->res));
}
/**
* @expectedException \RuntimeException
*/
public function testAvoidInfiniteLoopWhenNoDataIsWrittenForAWritingTimeoutSeconds()
{
$this->setMockHandler(array('fwrite', 'streamGetMetadata'));
$this->handler->expects($this->any())
->method('fwrite')
->will($this->returnValue(0));
$this->handler->expects($this->any())
->method('streamGetMetadata')
->will($this->returnValue(array('timed_out' => false)));
$this->handler->setWritingTimeout(1);
$this->writeRecord('Hello world');
}
private function createHandler($connectionString)
{
$this->handler = new SocketHandler($connectionString);