Thread worker tests

This commit is contained in:
Aaron Piotrowski 2023-12-27 12:31:22 -06:00
parent 8984c838c2
commit f013263aff
No known key found for this signature in database
GPG Key ID: 5B456E6AABA44A63
3 changed files with 52 additions and 3 deletions

View File

@ -7,9 +7,6 @@ use Amp\Parallel\Context\Context;
use Amp\Parallel\Context\ContextFactory;
use Amp\Parallel\Context\ProcessContextFactory;
/**
* @group process
*/
class ProcessPoolTest extends AbstractPoolTest
{
public function createContextFactory(): ContextFactory

View File

@ -0,0 +1,26 @@
<?php declare(strict_types=1);
namespace Amp\Parallel\Test\Worker;
use Amp\Cancellation;
use Amp\Parallel\Context\Context;
use Amp\Parallel\Context\ContextFactory;
use Amp\Parallel\Context\ThreadContext;
use Amp\Parallel\Context\ThreadContextFactory;
class ThreadPoolTest extends AbstractPoolTest
{
public function createContextFactory(): ContextFactory
{
if (!ThreadContext::isSupported()) {
$this->markTestSkipped('ext-parallel required');
}
return new class implements ContextFactory {
public function start(array|string $script, ?Cancellation $cancellation = null): Context
{
return (new ThreadContextFactory())->start($script, cancellation: $cancellation);
}
};
}
}

View File

@ -0,0 +1,26 @@
<?php declare(strict_types=1);
namespace Amp\Parallel\Test\Worker;
use Amp\Cancellation;
use Amp\Parallel\Context\Context;
use Amp\Parallel\Context\ContextFactory;
use Amp\Parallel\Context\ThreadContext;
use Amp\Parallel\Context\ThreadContextFactory;
class ThreadWorkerTest extends AbstractWorkerTest
{
public function createContextFactory(): ContextFactory
{
if (!ThreadContext::isSupported()) {
$this->markTestSkipped('ext-parallel required');
}
return new class implements ContextFactory {
public function start(array|string $script, ?Cancellation $cancellation = null): Context
{
return (new ThreadContextFactory())->start($script, cancellation: $cancellation);
}
};
}
}