Initial commit
This commit is contained in:
85
tests/Signal/SignalHandlerTest.php
Normal file
85
tests/Signal/SignalHandlerTest.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\Ipc\Signal;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class SignalHandlerTest extends \PhpUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
public function testSignalHandlerWithSingleHandlerInConstructor()
|
||||
{
|
||||
$callbacks = [
|
||||
function () use (&$handler1) { $handler1 = true; }
|
||||
];
|
||||
|
||||
$handler = new SignalHandler(SIGUSR1, $callbacks);
|
||||
|
||||
posix_kill(posix_getpid(), SIGUSR1);
|
||||
|
||||
usleep(1000);
|
||||
|
||||
$this->assertEquals(true, $handler1);
|
||||
}
|
||||
|
||||
public function testSignalHandlerWithMultipleHandlersInConstructor()
|
||||
{
|
||||
$callbacks = [
|
||||
function () use (&$handler1) { $handler1 = true; },
|
||||
function () use (&$handler2) { $handler2 = true; },
|
||||
function () use (&$handler3) { $handler3 = true; }
|
||||
];
|
||||
|
||||
$handler = new SignalHandler(SIGUSR1, $callbacks);
|
||||
|
||||
posix_kill(posix_getpid(), SIGUSR1);
|
||||
|
||||
usleep(1000);
|
||||
|
||||
$this->assertEquals(true, $handler1);
|
||||
$this->assertEquals(true, $handler2);
|
||||
$this->assertEquals(true, $handler3);
|
||||
}
|
||||
|
||||
public function testSignalHandlerWithAddedHandlers()
|
||||
{
|
||||
$callbacks = [
|
||||
function () use (&$handler1) { $handler1 = true; },
|
||||
function () use (&$handler2) { $handler2 = true; }
|
||||
];
|
||||
|
||||
$handler = new SignalHandler(SIGUSR1, $callbacks);
|
||||
|
||||
$handler->addHandler(function () use (&$handler3) { $handler3 = true; });
|
||||
|
||||
posix_kill(posix_getpid(), SIGUSR1);
|
||||
|
||||
usleep(1000);
|
||||
|
||||
$this->assertEquals(true, $handler1);
|
||||
$this->assertEquals(true, $handler2);
|
||||
$this->assertEquals(true, $handler3);
|
||||
}
|
||||
|
||||
public function testSignalHandlerWithBlockingHandler()
|
||||
{
|
||||
$callbacks = [
|
||||
function () use (&$handler1) { $handler1 = true; return true; },
|
||||
function () use (&$handler2) { $handler2 = true; },
|
||||
function () use (&$handler3) { $handler3 = true; }
|
||||
];
|
||||
|
||||
$handler = new SignalHandler(SIGUSR1, $callbacks);
|
||||
|
||||
posix_kill(posix_getpid(), SIGUSR1);
|
||||
|
||||
usleep(1000);
|
||||
|
||||
$this->assertEquals(true, $handler1);
|
||||
$this->assertEquals(false, $handler2);
|
||||
$this->assertEquals(false, $handler3);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user