File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,13 @@ public function createDeferredShell($process)
38
38
39
39
$ stream = new CompositeStream ($ process ->stdout , $ process ->stdin );
40
40
41
+ // forcefully terminate process when stream closes
42
+ $ stream ->on ('close ' , function () use ($ process ) {
43
+ if ($ process ->isRunning ()) {
44
+ $ process ->terminate (SIGKILL );
45
+ }
46
+ });
47
+
41
48
return new DeferredShell ($ stream );
42
49
}
43
50
}
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
3
use Clue \React \Shell \ProcessLauncher ;
4
+ use React \Stream \ReadableStream ;
4
5
5
6
class ProcessLauncherTest extends TestCase
6
7
{
@@ -25,4 +26,32 @@ public function testProcessWillBeStarted()
25
26
26
27
$ this ->assertInstanceOf ('Clue\React\Shell\DeferredShell ' , $ shell );
27
28
}
29
+
30
+ public function testClosingStreamTerminatesRunningProcess ()
31
+ {
32
+ $ process = $ this ->getMockBuilder ('React\ChildProcess\Process ' )->disableOriginalConstructor ()->getMock ();
33
+ $ process ->stdout = new ReadableStream ();
34
+ $ process ->stdin = $ this ->getMock ('React\Stream\WritableStreamInterface ' );
35
+
36
+ $ process ->expects ($ this ->once ())->method ('isRunning ' )->will ($ this ->returnValue (true ));
37
+ $ process ->expects ($ this ->once ())->method ('terminate ' )->with ($ this ->equalTo (SIGKILL ));
38
+
39
+ $ shell = $ this ->processLauncher ->createDeferredShell ($ process );
40
+
41
+ $ shell ->close ();
42
+ }
43
+
44
+ public function testClosingStreamOfNonRunningProcessWillNotTerminate ()
45
+ {
46
+ $ process = $ this ->getMockBuilder ('React\ChildProcess\Process ' )->disableOriginalConstructor ()->getMock ();
47
+ $ process ->stdout = new ReadableStream ();
48
+ $ process ->stdin = $ this ->getMock ('React\Stream\WritableStreamInterface ' );
49
+
50
+ $ process ->expects ($ this ->once ())->method ('isRunning ' )->will ($ this ->returnValue (false ));
51
+ $ process ->expects ($ this ->never ())->method ('terminate ' );
52
+
53
+ $ shell = $ this ->processLauncher ->createDeferredShell ($ process );
54
+
55
+ $ shell ->close ();
56
+ }
28
57
}
You can’t perform that action at this time.
0 commit comments