22
33namespace Laravel \Octane \Tests ;
44
5+ use Laravel \Octane \Exec ;
56use Laravel \Octane \Swoole \ServerProcessInspector ;
67use Laravel \Octane \Swoole \ServerStateFile ;
78use Laravel \Octane \Swoole \SignalDispatcher ;
@@ -14,7 +15,8 @@ public function test_can_determine_if_swoole_server_process_is_running_when_mana
1415 {
1516 $ inspector = new ServerProcessInspector (
1617 $ dispatcher = Mockery::mock (SignalDispatcher::class),
17- $ processIdFile = new ServerStateFile (sys_get_temp_dir ().'/swoole.pid ' )
18+ $ processIdFile = new ServerStateFile (sys_get_temp_dir ().'/swoole.pid ' ),
19+ Mockery::mock (Exec::class),
1820 );
1921
2022 $ dispatcher ->shouldReceive ('canCommunicateWith ' )->with (2 )->andReturn (true );
@@ -31,7 +33,8 @@ public function test_can_determine_if_swoole_server_process_is_running_when_mana
3133 {
3234 $ inspector = new ServerProcessInspector (
3335 $ dispatcher = Mockery::mock (SignalDispatcher::class),
34- $ processIdFile = new ServerStateFile (sys_get_temp_dir ().'/swoole.pid ' )
36+ $ processIdFile = new ServerStateFile (sys_get_temp_dir ().'/swoole.pid ' ),
37+ Mockery::mock (Exec::class),
3538 );
3639
3740 $ dispatcher ->shouldReceive ('canCommunicateWith ' )->with (2 )->andReturn (false );
@@ -48,7 +51,8 @@ public function test_can_determine_if_swoole_server_process_is_running_when_only
4851 {
4952 $ inspector = new ServerProcessInspector (
5053 $ dispatcher = Mockery::mock (SignalDispatcher::class),
51- $ processIdFile = new ServerStateFile (sys_get_temp_dir ().'/swoole.pid ' )
54+ $ processIdFile = new ServerStateFile (sys_get_temp_dir ().'/swoole.pid ' ),
55+ Mockery::mock (Exec::class),
5256 );
5357
5458 $ dispatcher ->shouldReceive ('canCommunicateWith ' )->with (1 )->andReturn (true );
@@ -65,7 +69,8 @@ public function test_can_determine_if_swoole_server_process_is_running_when_mast
6569 {
6670 $ inspector = new ServerProcessInspector (
6771 $ dispatcher = Mockery::mock (SignalDispatcher::class),
68- $ processIdFile = new ServerStateFile (sys_get_temp_dir ().'/swoole.pid ' )
72+ $ processIdFile = new ServerStateFile (sys_get_temp_dir ().'/swoole.pid ' ),
73+ Mockery::mock (Exec::class),
6974 );
7075
7176 $ dispatcher ->shouldReceive ('canCommunicateWith ' )->with (1 )->andReturn (false );
@@ -76,4 +81,27 @@ public function test_can_determine_if_swoole_server_process_is_running_when_mast
7681
7782 $ processIdFile ->delete ();
7883 }
84+
85+ public function test_swoole_server_process_can_be_stop ()
86+ {
87+ $ inspector = new ServerProcessInspector (
88+ $ dispatcher = Mockery::mock (SignalDispatcher::class),
89+ $ processIdFile = new ServerStateFile (sys_get_temp_dir ().'/swoole.pid ' ),
90+ $ exec = Mockery::mock (Exec::class),
91+ );
92+
93+ $ processIdFile ->writeProcessIds (3 , 2 );
94+ $ exec ->shouldReceive ('run ' )->once ()->with ('pgrep -P 2 ' )->andReturn ([4 , 5 ]);
95+
96+ collect ([2 , 3 , 4 , 5 ])->each (
97+ fn ($ processId ) => $ dispatcher
98+ ->shouldReceive ('signal ' )
99+ ->with ($ processId , SIGKILL )
100+ ->once (),
101+ );
102+
103+ $ this ->assertTrue ($ inspector ->stopServer ());
104+
105+ $ processIdFile ->delete ();
106+ }
79107}
0 commit comments