-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathManagerTest.php
More file actions
72 lines (61 loc) · 2.43 KB
/
Copy pathManagerTest.php
File metadata and controls
72 lines (61 loc) · 2.43 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
namespace Tests\Integration;
use ADT\BackgroundQueue\Broker\PhpAmqpLib\Manager;
use Codeception\Test\Unit;
use Tests\Support\IntegrationTester;
/**
* Testuje pojmenování front v Manageru se zaměřením na label-specific DIE fronty
* (feature pro cílený restart konzumerů). Čistá logika - nepotřebuje DB ani RabbitMQ.
*/
class ManagerTest extends Unit
{
protected IntegrationTester $tester;
private function getManager(): Manager
{
return new Manager([], ['arguments' => []]);
}
public function testGetTopPriorityNameWithoutLabel()
{
// Bez labelu zůstává sdílená top-priority (DIE) fronta "0".
$this->tester->assertSame('0', $this->getManager()->getTopPriorityName());
$this->tester->assertSame('0', $this->getManager()->getTopPriorityName(null));
}
public function testGetTopPriorityNameWithLabel()
{
// S labelem vznikne samostatná DIE fronta "0_<label>".
$this->tester->assertSame('0_consumer1', $this->getManager()->getTopPriorityName('consumer1'));
}
public function testGetTopPriorityNameRejectsLabelWithDelimiter()
{
// Label se vkládá do názvu fronty za oddělovač "_", takže ho sám obsahovat nesmí.
try {
$this->getManager()->getTopPriorityName('foo_bar');
$this->tester->fail('Očekávána výjimka pro label obsahující "_".');
} catch (\Exception $e) {
$this->tester->assertSame('Label cannot contain "_".', $e->getMessage());
}
}
public function testIncludeTopPriorityPrependsSharedQueue()
{
// Top-priority fronta se vkládá na začátek, aby ji konzumer kontroloval jako první.
$this->tester->assertSame(['0', 10, 20], $this->getManager()->includeTopPriority([10, 20]));
}
public function testIncludeTopPriorityPrependsLabelledQueue()
{
$this->tester->assertSame(['0_worker', 10, 20], $this->getManager()->includeTopPriority([10, 20], 'worker'));
}
public function testGetQueueWithPriority()
{
$this->tester->assertSame('general_10', $this->getManager()->getQueueWithPriority('general', '10'));
}
public function testGetQueueWithPrioritySupportsNamedQueueAndLabelledTopPriority()
{
// Regrese: pojmenovaná fronta (obsahuje "_") v kombinaci s label DIE prioritou ("0_label")
// musí projít. Dřívější kontrola na "_" v názvu fronty by tohle chybně odmítla.
$manager = $this->getManager();
$this->tester->assertSame(
'general_myqueue_0_worker',
$manager->getQueueWithPriority('general_myqueue', $manager->getTopPriorityName('worker'))
);
}
}