mirror of
https://github.com/danog/parallel.git
synced 2025-01-22 14:01:14 +01:00
Fail queued tasks after shutdown is invoked
This commit is contained in:
parent
d81b6fccd2
commit
ca051a0aa6
@ -71,7 +71,7 @@ abstract class AbstractWorker implements Worker {
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->context->isRunning()) {
|
||||
if ($this->shutdown || !$this->context->isRunning()) {
|
||||
throw new WorkerException("The worker was shutdown");
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ use Amp\Parallel\Sync\SerializationException;
|
||||
use Amp\Parallel\Worker\Environment;
|
||||
use Amp\Parallel\Worker\Task;
|
||||
use Amp\Parallel\Worker\TaskError;
|
||||
use Amp\Parallel\Worker\WorkerException;
|
||||
use Amp\PHPUnit\TestCase;
|
||||
|
||||
class NonAutoloadableTask implements Task {
|
||||
@ -97,10 +98,34 @@ abstract class AbstractWorkerTest extends TestCase {
|
||||
});
|
||||
}
|
||||
|
||||
yield $promises; // Wait until all tasks have finished before invoking $worker->shutdown().
|
||||
|
||||
yield $worker->shutdown();
|
||||
});
|
||||
}
|
||||
|
||||
public function testEnqueueMultipleThenShutdown() {
|
||||
Loop::run(function () {
|
||||
$worker = $this->createWorker();
|
||||
|
||||
$promises = [
|
||||
$worker->enqueue(new TestTask(42, 200)),
|
||||
$worker->enqueue(new TestTask(56, 300)),
|
||||
$worker->enqueue(new TestTask(72, 100))
|
||||
];
|
||||
|
||||
yield $worker->shutdown();
|
||||
|
||||
\array_shift($promises); // First task will succeed.
|
||||
|
||||
foreach ($promises as $promise) {
|
||||
$promise->onResolve(function ($e, $v) {
|
||||
$this->assertInstanceOf(WorkerException::class, $e);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function testNotIdleOnEnqueue() {
|
||||
Loop::run(function () {
|
||||
$worker = $this->createWorker();
|
||||
|
Loading…
x
Reference in New Issue
Block a user