Skip to content

Commit 3d1e5f7

Browse files
committed
Additional tests to ensure process exit is detected after pipes close
1 parent f72aca3 commit 3d1e5f7

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

tests/AbstractProcessTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,47 @@ public function testDetectsClosingStdoutWithoutHavingToWaitForExit()
278278
$this->assertTrue($closed);
279279
}
280280

281+
public function testKeepsRunningEvenWhenAllStdioPipesHaveBeenClosed()
282+
{
283+
$cmd = 'exec ' . $this->getPhpBinary() . ' -r ' . escapeshellarg('fclose(STDIN);fclose(STDOUT);fclose(STDERR);sleep(1);');
284+
285+
$loop = $this->createLoop();
286+
$process = new Process($cmd);
287+
$process->start($loop);
288+
289+
$closed = 0;
290+
$process->stdout->on('close', function () use (&$closed) {
291+
++$closed;
292+
});
293+
$process->stderr->on('close', function () use (&$closed) {
294+
++$closed;
295+
});
296+
297+
// run loop for 0.1s only
298+
$loop->addTimer(0.1, function () use ($loop) {
299+
$loop->stop();
300+
});
301+
$loop->run();
302+
303+
$this->assertEquals(2, $closed);
304+
$this->assertTrue($process->isRunning());
305+
}
306+
307+
public function testDetectsClosingProcessEvenWhenAllStdioPipesHaveBeenClosed()
308+
{
309+
$cmd = 'exec ' . $this->getPhpBinary() . ' -r ' . escapeshellarg('fclose(STDIN);fclose(STDOUT);fclose(STDERR);usleep(10000);');
310+
311+
$loop = $this->createLoop();
312+
$process = new Process($cmd);
313+
$process->start($loop, 0.001);
314+
315+
$time = microtime(true);
316+
$loop->run();
317+
$time = microtime(true) - $time;
318+
319+
$this->assertLessThan(0.1, $time);
320+
}
321+
281322
public function testStartInvalidProcess()
282323
{
283324
$cmd = tempnam(sys_get_temp_dir(), 'react');

0 commit comments

Comments
 (0)