@@ -84,6 +84,56 @@ public function testStartWithCustomPipesWillAssignPipes()
84
84
$ this ->assertInstanceOf ('React\Stream\WritableStreamInterface ' , $ process ->pipes [3 ]);
85
85
}
86
86
87
+ /**
88
+ * @expectedException RuntimeException
89
+ * @expectedExceptionMessage No such file or directory
90
+ */
91
+ public function testStartWithInvalidFileDescriptorPathWillThrow ()
92
+ {
93
+ $ fds = array (
94
+ 4 => array ('file ' , '/dev/does-not-exist ' , 'r ' )
95
+ );
96
+
97
+ $ process = new Process ('exit 0 ' , null , null , $ fds );
98
+ $ process ->start ($ this ->createLoop ());
99
+ }
100
+
101
+ public function testStartWithExcessiveNumberOfFileDescriptorsWillThrow ()
102
+ {
103
+ if (PHP_VERSION_ID < 70000 ) {
104
+ $ this ->markTestSkipped ('PHP 7+ only, causes memory overflow on legacy PHP 5 ' );
105
+ }
106
+
107
+ $ ulimit = exec ('ulimit -n 2>&1 ' );
108
+ if ($ ulimit < 1 ) {
109
+ $ this ->markTestSkipped ('Unable to determine limit of open files (ulimit not available?) ' );
110
+ }
111
+
112
+ $ loop = $ this ->createLoop ();
113
+
114
+ // create 70% (usually ~700) dummy file handles in this parent dummy
115
+ $ limit = (int )($ ulimit * 0.7 );
116
+ $ fds = array ();
117
+ for ($ i = 0 ; $ i < $ limit ; ++$ i ) {
118
+ $ fds [$ i ] = fopen ('/dev/null ' , 'r ' );
119
+ }
120
+
121
+ // try to create child process with another ~700 dummy file handles
122
+ $ new = array_fill (0 , $ limit , array ('file ' , '/dev/null ' , 'r ' ));
123
+ $ process = new Process ('ping example.com ' , null , null , $ new );
124
+
125
+ try {
126
+ $ process ->start ($ loop );
127
+
128
+ $ this ->fail ('Did not expect to reach this point ' );
129
+ } catch (\RuntimeException $ e ) {
130
+ // clear dummy files handles to make some room again (avoid fatal errors for autoloader)
131
+ $ fds = array ();
132
+
133
+ $ this ->assertContains ('Too many open files ' , $ e ->getMessage ());
134
+ }
135
+ }
136
+
87
137
public function testIsRunning ()
88
138
{
89
139
if (DIRECTORY_SEPARATOR === '\\' ) {
0 commit comments