-
Notifications
You must be signed in to change notification settings - Fork 305
/
Copy pathRoadRunnerServerProcessInspectorTest.php
76 lines (57 loc) · 2.43 KB
/
RoadRunnerServerProcessInspectorTest.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
<?php
namespace Laravel\Octane\Tests;
use Laravel\Octane\PosixExtension;
use Laravel\Octane\RoadRunner\Concerns\FindsRoadRunnerBinary;
use Laravel\Octane\RoadRunner\ServerProcessInspector;
use Laravel\Octane\RoadRunner\ServerStateFile;
use Laravel\Octane\SymfonyProcessFactory;
use Mockery;
class RoadRunnerServerProcessInspectorTest extends TestCase
{
use FindsRoadRunnerBinary;
public function test_can_determine_if_roadrunner_server_process_is_running_when_master_is_running()
{
$inspector = new ServerProcessInspector(
$processIdFile = new ServerStateFile(sys_get_temp_dir().'/swoole.pid'),
new SymfonyProcessFactory,
$posix = Mockery::mock(PosixExtension::class)
);
$posix->shouldReceive('kill')->with(1, 0)->andReturn(true);
$processIdFile->writeProcessId(1);
$this->assertTrue($inspector->serverIsRunning());
$processIdFile->delete();
}
public function test_can_determine_if_roadrunner_server_process_is_running_when_master_cant_be_communicated_with()
{
$inspector = new ServerProcessInspector(
$processIdFile = new ServerStateFile(sys_get_temp_dir().'/swoole.pid'),
new SymfonyProcessFactory,
$posix = Mockery::mock(PosixExtension::class)
);
$posix->shouldReceive('kill')->with(1, 0)->andReturn(false);
$processIdFile->writeProcessId(1);
$this->assertFalse($inspector->serverIsRunning());
$processIdFile->delete();
}
/** @doesNotPerformAssertions @test */
public function test_roadrunner_server_process_can_be_reloaded()
{
$this->createApplication();
$inspector = new ServerProcessInspector(
$processIdFile = new ServerStateFile(sys_get_temp_dir().'/swoole.pid'),
$processFactory = Mockery::mock(SymfonyProcessFactory::class),
new PosixExtension
);
$processIdFile->writeState([
'host' => '127.0.0.1',
'rpcPort' => '6002',
]);
$processFactory->shouldReceive('createProcess')->with(
[$this->findRoadRunnerBinary(), 'reset', '-o', 'server=3', '-o', 'rpc.listen=tcp://127.0.0.1:6002', '-s'],
base_path(),
)->andReturn($process = Mockery::mock('stdClass'));
$process->shouldReceive('start')->once()->andReturn(0);
$process->shouldReceive('waitUntil')->once();
$inspector->reloadServer();
}
}