1
0
Fork 0

Make async test more robust

pull/9310/head
Jordi Boggiano 2020-10-16 11:23:03 +02:00
parent c46b75de81
commit c01e3bd2f0
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 4 additions and 1 deletions

View File

@ -119,10 +119,13 @@ class ProcessExecutorTest extends TestCase
{ {
$process = new ProcessExecutor($buffer = new BufferIO('', StreamOutput::VERBOSITY_DEBUG)); $process = new ProcessExecutor($buffer = new BufferIO('', StreamOutput::VERBOSITY_DEBUG));
$process->enableAsync(); $process->enableAsync();
$start = microtime(true);
/** @var Promise $promise */ /** @var Promise $promise */
$promise = $process->executeAsync('echo foo'); $promise = $process->executeAsync('sleep 2');
$this->assertEquals(1, $process->countActiveJobs()); $this->assertEquals(1, $process->countActiveJobs());
$promise->cancel(); $promise->cancel();
$this->assertEquals(0, $process->countActiveJobs()); $this->assertEquals(0, $process->countActiveJobs());
$end = microtime(true);
$this->assertTrue($end - $start < 0.5, 'Canceling took longer than it should, lasted '.($end - $start));
} }
} }