1
0
mirror of https://github.com/danog/parallel.git synced 2024-12-02 17:52:14 +01:00
parallel/test/Context/ParallelTest.php

54 lines
1.2 KiB
PHP
Raw Normal View History

2019-02-13 21:19:01 +01:00
<?php
namespace Amp\Parallel\Test\Context;
use Amp\Parallel\Context\Context;
2019-02-13 21:19:01 +01:00
use Amp\Parallel\Context\Parallel;
/**
* @requires extension parallel
*/
class ParallelTest extends AbstractContextTest
2019-02-13 21:19:01 +01:00
{
public function createContext($script): Context
2019-02-13 21:19:01 +01:00
{
return new Parallel($script);
2019-02-13 21:19:01 +01:00
}
public function testGetId()
{
2019-08-27 19:17:41 +02:00
$context = $this->createContext([
__DIR__ . "/Fixtures/test-process.php",
"Test"
]);
2019-08-27 19:17:41 +02:00
yield $context->start();
$this->assertIsInt($context->getId());
yield $context->join();
2019-08-27 19:17:41 +02:00
$context = $this->createContext([
__DIR__ . "/Fixtures/test-process.php",
"Test"
]);
2019-08-27 19:17:41 +02:00
$this->expectException(\Error::class);
$this->expectExceptionMessage('The thread has not been started');
2019-08-27 19:17:41 +02:00
$context->getId();
}
public function testRunStartsThread()
{
2019-08-27 19:17:41 +02:00
$thread = yield Parallel::run([
__DIR__ . "/Fixtures/test-process.php",
"Test"
]);
2019-08-27 19:17:41 +02:00
$this->assertInstanceOf(Parallel::class, $thread);
$this->assertTrue($thread->isRunning());
$this->assertIsInt($thread->getId());
2019-08-27 19:17:41 +02:00
return yield $thread->join();
}
2019-02-13 21:19:01 +01:00
}