1
0
mirror of https://github.com/danog/amp.git synced 2024-12-03 18:07:57 +01:00
amp/test/SignalTrapTest.php

55 lines
1.2 KiB
PHP
Raw Normal View History

2020-10-10 16:06:49 +02:00
<?php
namespace Amp\Test;
use Amp\Loop;
use Amp\PHPUnit\AsyncTestCase;
use Amp\SignalTrap;
2020-10-10 16:06:49 +02:00
use function Amp\await;
use function Amp\trap;
2020-10-10 16:06:49 +02:00
/**
* @requires ext-pcntl
*/
class SignalTrapTest extends AsyncTestCase
2020-10-10 16:06:49 +02:00
{
public function testDelayed(): void
{
$this->setMinimumRuntime(20);
$promise = new SignalTrap(\SIGUSR1, \SIGUSR2);
2020-10-10 16:06:49 +02:00
Loop::delay(10, fn() => \posix_kill(\getmypid(), \SIGUSR1));
$this->assertSame(\SIGUSR1, await($promise));
$promise = new SignalTrap(\SIGUSR1, \SIGUSR2);
2020-10-10 16:06:49 +02:00
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 SignalTrap(\SIGUSR1, \SIGUSR2);
2020-10-10 16:06:49 +02:00
$promise->unreference();
$promise->reference();
await($promise);
}
public function testTrapFunction(): void
{
$this->setMinimumRuntime(10);
Loop::delay(10, fn() => \posix_kill(\getmypid(), \SIGUSR1));
trap(\SIGUSR1, \SIGUSR2);
}
2020-10-10 16:06:49 +02:00
}