mirror of
https://github.com/danog/parallel.git
synced 2024-12-02 09:37:57 +01:00
Fix failing Process::join()
If the process is killed while joining, an exception was thrown from Process::kill().
This commit is contained in:
parent
beafcdb140
commit
80c07011d6
@ -267,8 +267,10 @@ final class Process implements Context
|
|||||||
throw new SynchronizationError("Did not receive an exit result from process");
|
throw new SynchronizationError("Did not receive an exit result from process");
|
||||||
}
|
}
|
||||||
} catch (\Throwable $exception) {
|
} catch (\Throwable $exception) {
|
||||||
|
if ($this->isRunning()) {
|
||||||
$this->kill();
|
$this->kill();
|
||||||
throw $exception;
|
}
|
||||||
|
throw new ContextException("Failed to receive result from process", 0, $exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->channel->close();
|
$this->channel->close();
|
||||||
|
@ -35,12 +35,12 @@ class ProcessTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Amp\Parallel\Sync\PanicError
|
* @expectedException \Amp\Parallel\Sync\PanicError
|
||||||
* @expectedExceptionMessage No script found at 'test-process.php'
|
* @expectedExceptionMessage No script found at '../test-process.php'
|
||||||
*/
|
*/
|
||||||
public function testInvalidScriptPath()
|
public function testInvalidScriptPath()
|
||||||
{
|
{
|
||||||
Loop::run(function () {
|
Loop::run(function () {
|
||||||
$process = new Process("test-process.php");
|
$process = new Process("../test-process.php");
|
||||||
yield $process->start();
|
yield $process->start();
|
||||||
yield $process->join();
|
yield $process->join();
|
||||||
});
|
});
|
||||||
@ -84,4 +84,23 @@ class ProcessTest extends TestCase
|
|||||||
\var_dump(yield $process->join());
|
\var_dump(yield $process->join());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Amp\Parallel\Context\ContextException
|
||||||
|
* @expectedExceptionMessage Failed to receive result from process
|
||||||
|
*/
|
||||||
|
public function testKillWhenJoining()
|
||||||
|
{
|
||||||
|
Loop::run(function () {
|
||||||
|
$process = new Process([
|
||||||
|
__DIR__ . "/sleep-process.php",
|
||||||
|
5,
|
||||||
|
]);
|
||||||
|
yield $process->start();
|
||||||
|
$promise = $process->join();
|
||||||
|
$process->kill();
|
||||||
|
$this->assertFalse($process->isRunning());
|
||||||
|
yield $promise;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
7
test/Context/sleep-process.php
Normal file
7
test/Context/sleep-process.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Amp\Parallel\Sync\Channel;
|
||||||
|
|
||||||
|
return function (Channel $channel) use ($argv) {
|
||||||
|
\sleep((int) ($argv[1] ?? 1));
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user