-
Notifications
You must be signed in to change notification settings - Fork 664
/
Copy pathProvisioningPlanTest.php
118 lines (99 loc) · 3.95 KB
/
ProvisioningPlanTest.php
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
namespace Laravel\Horizon\Tests\Feature;
use Illuminate\Support\Facades\Redis;
use Laravel\Horizon\MasterSupervisor;
use Laravel\Horizon\MasterSupervisorCommands\AddSupervisor;
use Laravel\Horizon\ProvisioningPlan;
use Laravel\Horizon\Tests\IntegrationTest;
class ProvisioningPlanTest extends IntegrationTest
{
public function test_supervisors_are_added()
{
$plan = [
'production' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => 'first',
'max_processes' => 20,
],
],
];
$plan = new ProvisioningPlan(MasterSupervisor::name(), $plan);
$plan->deploy('production');
$commands = Redis::connection('horizon')->lrange(
'commands:'.MasterSupervisor::commandQueueFor(MasterSupervisor::name()), 0, -1
);
$this->assertCount(1, $commands);
$command = (object) json_decode($commands[0], true);
$this->assertSame(AddSupervisor::class, $command->command);
$this->assertSame('first', $command->options['queue']);
$this->assertSame(20, $command->options['maxProcesses']);
}
public function test_supervisors_are_added_by_wildcard()
{
$plan = [
'production' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => 'first',
'max_processes' => 20,
],
],
];
$plan = new ProvisioningPlan(MasterSupervisor::name(), $plan);
$plan->deploy('production');
$commands = Redis::connection('horizon')->lrange(
'commands:'.MasterSupervisor::commandQueueFor(MasterSupervisor::name()), 0, -1
);
$this->assertCount(1, $commands);
$command = (object) json_decode($commands[0], true);
$this->assertSame(AddSupervisor::class, $command->command);
$this->assertSame('first', $command->options['queue']);
$this->assertSame(20, $command->options['maxProcesses']);
}
public function test_plan_is_converted_into_array_of_supervisor_options()
{
$plan = [
'production' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => 'default',
'balance' => true,
'auto_scale' => true,
],
'supervisor-2' => [
'connection' => 'redis',
'queue' => 'default',
],
],
'local' => [
'supervisor-2' => [
'connection' => 'redis',
'queue' => 'local-supervisor-2-queue',
'max_processes' => 20,
],
],
];
$results = (new ProvisioningPlan(MasterSupervisor::name(), $plan))->toSupervisorOptions();
$this->assertSame(MasterSupervisor::name().':supervisor-1', $results['production']['supervisor-1']->name);
$this->assertSame('redis', $results['production']['supervisor-1']->connection);
$this->assertSame('default', $results['production']['supervisor-1']->queue);
$this->assertTrue($results['production']['supervisor-1']->balance);
$this->assertTrue($results['production']['supervisor-1']->autoScale);
$this->assertSame(20, $results['local']['supervisor-2']->maxProcesses);
}
public function test_backoff_is_translated_to_string_form()
{
$plan = [
'local' => [
'supervisor-2' => [
'connection' => 'redis',
'queue' => 'local-supervisor-2-queue',
'backoff' => [30, 60],
],
],
];
$results = (new ProvisioningPlan(MasterSupervisor::name(), $plan))->toSupervisorOptions();
$this->assertSame('30,60', $results['local']['supervisor-2']->backoff);
}
}