-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
211 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Amp\Parallel\Test\Sync; | ||
|
||
use Amp\Parallel\Sync\ChannelParser; | ||
use Amp\PHPUnit\TestCase; | ||
|
||
class ChannelParserTest extends TestCase { | ||
/** | ||
* @expectedException \Amp\Parallel\Sync\SerializationException | ||
* @expectedExceptionMessage Exception thrown when unserializing data | ||
*/ | ||
public function testCorruptedData() { | ||
$data = "Invalid serialized data"; | ||
$data = \pack("CL", 0, \strlen($data)) . $data; | ||
$parser = new ChannelParser($this->createCallback(0)); | ||
$parser->push($data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Amp\Parallel\Test\Sync; | ||
|
||
use Amp\Parallel\Sync\ExitFailure; | ||
use Amp\Parallel\Sync\PanicError; | ||
use Amp\PHPUnit\TestCase; | ||
|
||
class ExitFailureTest extends TestCase { | ||
public function testGetResult() { | ||
$message = "Test message"; | ||
$exception = new \Exception($message); | ||
$result = new ExitFailure($exception); | ||
try { | ||
$result->getResult(); | ||
} catch (PanicError $caught) { | ||
$this->assertGreaterThan(0, \stripos($caught->getMessage(), $message)); | ||
return; | ||
} | ||
|
||
$this->fail(\sprintf("Exception should be thrown from %s::getResult()", ExitFailure::class)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Amp\Parallel\Test\Sync; | ||
|
||
use Amp\Parallel\Sync\ExitSuccess; | ||
use Amp\PHPUnit\TestCase; | ||
|
||
class ExitSuccessTest extends TestCase { | ||
public function testGetResult() { | ||
$value = 1; | ||
$result = new ExitSuccess($value); | ||
$this->assertSame($value, $result->getResult()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Amp\Parallel\Test\Worker; | ||
|
||
use Amp\Parallel\Worker\DefaultWorkerFactory; | ||
use Amp\Parallel\Worker\Worker; | ||
use Amp\PHPUnit\TestCase; | ||
|
||
class DefaultWorkerFactoryTest extends TestCase { | ||
/** | ||
* @expectedException \Error | ||
* @expectedExceptionMessage Invalid environment class name 'Invalid' | ||
*/ | ||
public function testInvalidClassName() { | ||
$factory = new DefaultWorkerFactory("Invalid"); | ||
} | ||
|
||
/** | ||
* @expectedException \Error | ||
* @expectedExceptionMessage does not implement 'Amp\Parallel\Worker\Environment' | ||
*/ | ||
public function testNonEnvironmentClassName() { | ||
$factory = new DefaultWorkerFactory(DefaultWorkerFactory::class); | ||
} | ||
|
||
public function testCreate() { | ||
$factory = new DefaultWorkerFactory; | ||
|
||
$this->assertInstanceOf(Worker::class, $factory->create()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Amp\Parallel\Test\Worker; | ||
|
||
use Amp\Parallel\Worker\Internal\Job; | ||
use Amp\PHPUnit\TestCase; | ||
|
||
class JobTest extends TestCase { | ||
public function testGetJob() { | ||
$task = new TestTask(42); | ||
$job = new Job($task); | ||
$this->assertSame($task, $job->getTask()); | ||
} | ||
|
||
/** | ||
* @expectedException \Error | ||
* @expectedExceptionMessage Classes implementing Amp\Parallel\Worker\Task must be autoloadable by the Composer autoloader | ||
*/ | ||
public function testUnserialiableClass() { | ||
$task = new TestTask(42); | ||
$job = new Job($task); | ||
$serialized = \serialize($job); | ||
$job = \unserialize($serialized, ['allowed_classes' => [Job::class]]); | ||
$task = $job->getTask(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Amp\Parallel\Test\Worker; | ||
|
||
use Amp\Parallel\Worker\Internal\TaskFailure; | ||
use Amp\Parallel\Worker\Worker; | ||
use Amp\PHPUnit\TestCase; | ||
use Amp\Promise; | ||
|
||
class TaskFailureTest extends TestCase { | ||
/** | ||
* @expectedException \Amp\Parallel\Worker\TaskException | ||
* @expectedExceptionMessage Uncaught Exception in worker | ||
*/ | ||
public function testWithException() { | ||
$exception = new \Exception("Message", 1); | ||
$result = new TaskFailure('a', $exception); | ||
Promise\wait($result->promise()); | ||
} | ||
|
||
/** | ||
* @expectedException \Amp\Parallel\Worker\TaskError | ||
* @expectedExceptionMessage Uncaught Error in worker | ||
*/ | ||
public function testWithError() { | ||
$exception = new \Error("Message", 1); | ||
$result = new TaskFailure('a', $exception); | ||
Promise\wait($result->promise()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Amp\Parallel\Test\Worker; | ||
|
||
use Amp\Parallel\Worker\Internal\TaskSuccess; | ||
use Amp\PHPUnit\TestCase; | ||
use Amp\Promise; | ||
|
||
class TaskSuccessTest extends TestCase { | ||
public function testGetId() { | ||
$id = 'a'; | ||
$result = new TaskSuccess($id, 1); | ||
$this->assertSame($id, $result->getId()); | ||
} | ||
|
||
public function testPromise() { | ||
$value = 1; | ||
$result = new TaskSuccess('a', $value); | ||
$this->assertSame($value, Promise\wait($result->promise())); | ||
} | ||
} |