parallel-functions/test/ParallelTest.php
Aaron Piotrowski 6ff9ee6c4c
Add Pool parameter to function
Allows specifying a specific worker pool instead of the global pool.
2017-12-16 11:06:37 -06:00

37 lines
917 B
PHP

<?php
namespace Amp\ParallelFunctions\Test;
use Amp\Parallel\Worker\Pool;
use Amp\PHPUnit\TestCase;
use Amp\Promise;
use Amp\Success;
use function Amp\ParallelFunctions\parallel;
class ParallelTest extends TestCase {
/**
* @expectedException \Error
* @expectedExceptionMessage Unsupported callable: Serialization of 'class@anonymous' is not allowed
*/
public function testUnserializableClosure() {
$unserializable = new class {
};
parallel(function () use ($unserializable) {
return 1;
});
}
public function testCustomPool() {
$mock = $this->createMock(Pool::class);
$mock->expects($this->once())
->method("enqueue")
->willReturn(new Success(1));
$callable = parallel(function () {
return 0;
}, $mock);
$this->assertSame(1, Promise\wait($callable()));
}
}