Skip to content

Commit

Permalink
Adds Signal (#5)
Browse files Browse the repository at this point in the history
* Added test cases.

Co-authored-by: 李铭昕 <715557344@qq.com>
  • Loading branch information
huangdijia and limingxinleo authored Sep 5, 2022
1 parent faaac0a commit 59caf26
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Signal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Engine;

use Hyperf\Engine\Contract\SignalInterface;
use Swoole\Coroutine\System;

class Signal implements SignalInterface
{
public static function wait(int $signo, float $timeout = -1): bool
{
return System::waitSignal($signo, $timeout);
}
}
37 changes: 37 additions & 0 deletions tests/Cases/SignalTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace HyperfTest\Cases;

use Hyperf\Engine\Signal;

/**
* @internal
* @coversNothing
*/
class SignalTest extends AbstractTestCase
{
public function testSignal()
{
$this->runInCoroutine(function () {
$res = Signal::wait(SIGUSR1, 1);
$this->assertFalse($res);

go(static function () {
sleep(1);
posix_kill(getmypid(), SIGUSR1);
});

$res = Signal::wait(SIGUSR1, 2);
$this->assertTrue($res);
});
}
}

0 comments on commit 59caf26

Please sign in to comment.