|
1
|
|
|
<?php |
|
2
|
|
|
namespace Slince\Process\Tests\SystemV; |
|
3
|
|
|
|
|
4
|
|
|
use PHPUnit\Framework\TestCase; |
|
5
|
|
|
use Slince\Process\Process; |
|
6
|
|
|
use Slince\Process\SystemV\MessageQueue; |
|
7
|
|
|
|
|
8
|
|
|
class MessageQueueTest extends TestCase |
|
9
|
|
|
{ |
|
10
|
|
|
public function testSend() |
|
11
|
|
|
{ |
|
12
|
|
|
$queue = new MessageQueue(); |
|
13
|
|
|
$this->assertTrue($queue->send('hello')); |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
public function testReceive() |
|
17
|
|
|
{ |
|
18
|
|
|
$process = new Process(function () { |
|
19
|
|
|
$queue = new MessageQueue(); |
|
20
|
|
|
$queue->send('hello'); |
|
21
|
|
|
}); |
|
22
|
|
|
$process->start(); |
|
23
|
|
|
$process->wait(); |
|
24
|
|
|
$queue = new MessageQueue(); |
|
25
|
|
|
$this->assertEquals('hello', $queue->receive()); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testBlockingReceive() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->markTestSkipped(); |
|
31
|
|
|
$process = new Process(function () { |
|
32
|
|
|
sleep(2); |
|
33
|
|
|
$queue = new MessageQueue(); |
|
34
|
|
|
$queue->send('hello'); |
|
35
|
|
|
}); |
|
36
|
|
|
$process->start(); |
|
37
|
|
|
$queue = new MessageQueue(); |
|
38
|
|
|
echo $queue->receive(false); |
|
39
|
|
|
echo $queue->receive(false); |
|
40
|
|
|
echo 'start'; |
|
41
|
|
|
$this->assertFalse($queue->receive(false)); |
|
42
|
|
|
echo 'end'; |
|
43
|
|
|
$this->assertEquals('hello', $queue->receive(true)); |
|
44
|
|
|
$process->wait(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testGetState() |
|
48
|
|
|
{ |
|
49
|
|
|
$queue = new MessageQueue(); |
|
50
|
|
|
$this->assertNotEmpty($queue->getState()); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testSetState() |
|
54
|
|
|
{ |
|
55
|
|
|
$queue = new MessageQueue(); |
|
56
|
|
|
$mode = $queue->getState()['msg_perm.mode']; |
|
57
|
|
|
$queue->setState('msg_perm.mode', $mode + 1); |
|
58
|
|
|
$this->assertEquals($mode + 1, $queue->getState()['msg_perm.mode']); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|