mirror of
https://github.com/danog/parallel-functions.git
synced 2024-12-02 09:37:56 +01:00
6ff9ee6c4c
Allows specifying a specific worker pool instead of the global pool.
37 lines
917 B
PHP
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()));
|
|
}
|
|
}
|