1
0
mirror of https://github.com/danog/amp.git synced 2024-12-02 17:37:50 +01:00
amp/test/SignalTest.php
2020-10-10 09:06:49 -05:00

45 lines
937 B
PHP

<?php
namespace Amp\Test;
use Amp\Loop;
use Amp\PHPUnit\AsyncTestCase;
use Amp\Signal;
use function Amp\await;
/**
* @requires ext-pcntl
*/
class SignalTest extends AsyncTestCase
{
public function testDelayed(): void
{
$this->setMinimumRuntime(20);
$promise = new Signal(\SIGUSR1, \SIGUSR2);
Loop::delay(10, fn() => \posix_kill(\getmypid(), \SIGUSR1));
$this->assertSame(\SIGUSR1, await($promise));
$promise = new Signal(\SIGUSR1, \SIGUSR2);
Loop::delay(10, fn() => \posix_kill(\getmypid(), \SIGUSR2));
$this->assertSame(\SIGUSR2, await($promise));
}
public function testReference(): void
{
$this->setMinimumRuntime(10);
Loop::delay(10, fn() => \posix_kill(\getmypid(), \SIGUSR1));
$promise = new Signal(\SIGUSR1, \SIGUSR2);
$promise->unreference();
$promise->reference();
await($promise);
}
}