public static function detectAsync(LoopInterface $loop, Collections $collections = null) { if ($collections === null) { $collections = getDefaultCollections($loop); } return $collections->getDetectors()->execute($collections->getCounters())->then(function (CountInterface $counter) { return $counter->execute(); })->then(function ($count) use($collections) { return $collections->getDetectors()->execute($collections->getAffinities())->then(function (AffinityInterface $affinity) use($count) { Resolver::setAffinity($affinity); return \React\Promise\resolve($count); }); }); }
public function testCreateFromClass() { $loop = Phake::mock('React\\EventLoop\\LoopInterface'); $poolPromise = CpuCoreCountFlexible::createFromClass('stdClass', $loop, [Options::DETECTOR => function ($loop) { $promise = new FulfilledPromise(); $affinity = Phake::mock('WyriHaximus\\CpuCoreDetector\\Core\\AffinityInterface'); Phake::when($affinity)->execute($this->isType('integer'), $this->isType('string'))->thenReturn($promise); Resolver::setAffinity($affinity); return new FulfilledPromise(4); }, Options::MIN_SIZE => 1, Options::MAX_SIZE => 1]); $this->assertInstanceOf('React\\Promise\\PromiseInterface', $poolPromise); $promiseHasResolved = false; $poolPromise->then(null, function ($exception) use(&$promiseHasResolved) { $this->assertInstanceOf('Exception', $exception); $this->assertSame('Given class doesn\'t implement ChildInterface', $exception->getMessage()); $promiseHasResolved = true; }); $this->assertTrue($promiseHasResolved); }
public function testRebuildProcessAndGetProcessPropertyValue() { $promise = new FulfilledPromise('taskset -c 13 a'); $affinity = Phake::mock('WyriHaximus\\CpuCoreDetector\\Core\\AffinityInterface'); Phake::when($affinity)->execute(13, 'a')->thenReturn($promise); Resolver::setAffinity($affinity); $process = new Process('a', 'b', ['c'], ['d']); $promiseResolved = false; \WyriHaximus\React\ChildProcess\Pool\rebuildProcess(13, $process)->then(function ($rebuildProcess) use(&$promiseResolved) { $this->assertSame('taskset -c 13 a', \WyriHaximus\React\ChildProcess\Pool\getProcessPropertyValue('cmd', $rebuildProcess)); $this->assertSame('b', \WyriHaximus\React\ChildProcess\Pool\getProcessPropertyValue('cwd', $rebuildProcess)); $this->assertSame(['c'], \WyriHaximus\React\ChildProcess\Pool\getProcessPropertyValue('env', $rebuildProcess)); $this->assertSame(['d'], \WyriHaximus\React\ChildProcess\Pool\getProcessPropertyValue('options', $rebuildProcess)); $promiseResolved = true; }); $this->assertTrue($promiseResolved); }