1
0
Fork 0

Added test to cancel ProcessExecutor::asyncExecute

pull/9188/head
Simon Berger 2020-09-08 11:33:41 +02:00
parent 8694077564
commit f3936b82cd
1 changed files with 12 additions and 0 deletions

View File

@ -16,6 +16,7 @@ use Composer\IO\ConsoleIO;
use Composer\Util\ProcessExecutor; use Composer\Util\ProcessExecutor;
use Composer\Test\TestCase; use Composer\Test\TestCase;
use Composer\IO\BufferIO; use Composer\IO\BufferIO;
use React\Promise\Promise;
use Symfony\Component\Console\Helper\HelperSet; use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput; use Symfony\Component\Console\Output\BufferedOutput;
@ -113,4 +114,15 @@ class ProcessExecutorTest extends TestCase
$process->execute('php -r "echo \'<error>foo</error>\'.PHP_EOL;"'); $process->execute('php -r "echo \'<error>foo</error>\'.PHP_EOL;"');
$this->assertSame('<error>foo</error>'.PHP_EOL, $output->fetch()); $this->assertSame('<error>foo</error>'.PHP_EOL, $output->fetch());
} }
public function testExecuteAsyncCancel()
{
$process = new ProcessExecutor($buffer = new BufferIO('', StreamOutput::VERBOSITY_DEBUG));
$process->enableAsync();
/** @var Promise $promise */
$promise = $process->executeAsync('echo foo');
$this->assertEquals(1, $process->countActiveJobs());
$promise->cancel();
$this->assertEquals(0, $process->countActiveJobs());
}
} }