-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added test cases. Co-authored-by: 李铭昕 <715557344@qq.com>
- Loading branch information
1 parent
faaac0a
commit 59caf26
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} | ||
} |