File: Bug458Test.php

package info (click to toggle)
php-amqplib 3.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,044 kB
  • sloc: php: 13,145; makefile: 77; sh: 27
file content (56 lines) | stat: -rw-r--r-- 1,390 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php

namespace PhpAmqpLib\Tests\Functional\Bug;

use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Tests\TestCaseCompat;
use PHPUnit\Framework\Attributes\Test;

/**
 * @group connection
 * @group signals
 */
class Bug458Test extends TestCaseCompat
{
    private $channel;

    protected function setUpCompat()
    {
        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();
    }

    protected function tearDownCompat()
    {
        if ($this->channel && $this->channel->is_open()) {
            $this->channel->close();
        }
        $this->channel = null;
    }

    /**
     * This test will be skipped in Windows, because pcntl extension is not available there
     */
    #[Test]
    public function stream_select_interruption()
    {
        $this->expectException(\PhpAmqpLib\Exception\AMQPTimeoutException::class);

        $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
        });
    }
}