Skip to content

Commit

Permalink
Thread worker tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Dec 27, 2023
1 parent 8984c83 commit f013263
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
3 changes: 0 additions & 3 deletions test/Worker/ProcessPoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
use Amp\Parallel\Context\ContextFactory;
use Amp\Parallel\Context\ProcessContextFactory;

/**
* @group process
*/
class ProcessPoolTest extends AbstractPoolTest
{
public function createContextFactory(): ContextFactory
Expand Down
26 changes: 26 additions & 0 deletions test/Worker/ThreadPoolTest.php
Original file line number Diff line number Diff line change
@@ -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);
}
};
}
}
26 changes: 26 additions & 0 deletions test/Worker/ThreadWorkerTest.php
Original file line number Diff line number Diff line change
@@ -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);
}
};
}
}

0 comments on commit f013263

Please sign in to comment.