forked from php-amqplib/php-amqplib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request php-amqplib#630 from Shivox/process-signal-handling
Fix and add test for signal handling with PCNTL extension
- Loading branch information
Showing
2 changed files
with
54 additions
and
9 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
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,44 @@ | ||
<?php | ||
|
||
namespace PhpAmqpLib\Tests\Functional\Bug; | ||
|
||
use PhpAmqpLib\Connection\AMQPStreamConnection; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class Bug458Test extends TestCase | ||
{ | ||
private $channel; | ||
|
||
public function setUp() | ||
{ | ||
if (!extension_loaded('pcntl')) { | ||
$this->markTestSkipped('pcntl extension is not available'); | ||
} | ||
|
||
$connection = new AMQPStreamConnection(HOST, PORT, USER, PASS, VHOST); | ||
|
||
$this->channel = $connection->channel(); | ||
$this->addSignalHandlers(); | ||
} | ||
|
||
/** | ||
* This test will be skipped in Windows, because pcntl extension is not available there | ||
* | ||
* @test | ||
* | ||
* @expectedException PhpAmqpLib\Exception\AMQPIOWaitException | ||
*/ | ||
public function stream_select_interruption() | ||
{ | ||
$pid = getmypid(); | ||
exec('php -r "sleep(1);posix_kill(' . $pid . ', SIGTERM);" > /dev/null 2>/dev/null &'); | ||
$this->channel->wait(null, false, 2); | ||
} | ||
|
||
private function addSignalHandlers() | ||
{ | ||
pcntl_signal(SIGTERM, function () { | ||
// do nothing | ||
}); | ||
} | ||
} |