diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/composer.json | 5 | ||||
-rw-r--r-- | tests/plugins/gzip/configs/.rr-http-withGzip.yaml | 2 | ||||
-rw-r--r-- | tests/plugins/http/http_plugin_test.go | 4 | ||||
-rw-r--r-- | tests/plugins/informer/test_plugin.go | 8 | ||||
-rw-r--r-- | tests/plugins/server/server_plugin_test.go | 2 | ||||
-rw-r--r-- | tests/psr-worker-bench.php | 11 | ||||
-rw-r--r-- | tests/src/Activity/SimpleActivity.php | 63 | ||||
-rw-r--r-- | tests/src/Client/StartNewWorkflow.php | 23 | ||||
-rw-r--r-- | tests/src/Workflow/SagaWorkflow.php | 54 |
9 files changed, 156 insertions, 16 deletions
diff --git a/tests/composer.json b/tests/composer.json index 52fa3a0e..cff9bd6b 100644 --- a/tests/composer.json +++ b/tests/composer.json @@ -7,5 +7,10 @@ "spiral/roadrunner-http": "^2.0", "temporal/sdk": ">=1.0", "spiral/tokenizer": ">=2.7" + }, + "autoload": { + "psr-4": { + "Temporal\\Tests\\": "src" + } } } diff --git a/tests/plugins/gzip/configs/.rr-http-withGzip.yaml b/tests/plugins/gzip/configs/.rr-http-withGzip.yaml index 3ab918fb..dc12dc05 100644 --- a/tests/plugins/gzip/configs/.rr-http-withGzip.yaml +++ b/tests/plugins/gzip/configs/.rr-http-withGzip.yaml @@ -2,8 +2,6 @@ server: command: "php ../../psr-worker.php" user: "" group: "" - env: - "RR_HTTP": "true" relay: "pipes" relay_timeout: "20s" diff --git a/tests/plugins/http/http_plugin_test.go b/tests/plugins/http/http_plugin_test.go index 9cd1c147..0b6fb77a 100644 --- a/tests/plugins/http/http_plugin_test.go +++ b/tests/plugins/http/http_plugin_test.go @@ -1216,10 +1216,12 @@ func TestHttpBrokenPipes(t *testing.T) { assert.NoError(t, err) err = cont.Init() - assert.Error(t, err) + assert.NoError(t, err) _, err = cont.Serve() assert.Error(t, err) + + assert.NoError(t, cont.Stop()) } func TestHTTPSupervisedPool(t *testing.T) { diff --git a/tests/plugins/informer/test_plugin.go b/tests/plugins/informer/test_plugin.go index 2300de89..8a1fb933 100644 --- a/tests/plugins/informer/test_plugin.go +++ b/tests/plugins/informer/test_plugin.go @@ -55,11 +55,5 @@ func (p1 *Plugin1) Workers() []worker.BaseProcess { panic(err) } - workers := p.Workers() - baseWorkers := make([]worker.BaseProcess, 0, len(workers)) - for i := 0; i < len(workers); i++ { - baseWorkers = append(baseWorkers, worker.FromSync(workers[i].(*worker.SyncWorkerImpl))) - } - - return baseWorkers + return p.Workers() } diff --git a/tests/plugins/server/server_plugin_test.go b/tests/plugins/server/server_plugin_test.go index f600832a..c0c3c993 100644 --- a/tests/plugins/server/server_plugin_test.go +++ b/tests/plugins/server/server_plugin_test.go @@ -278,7 +278,7 @@ func TestAppWrongRelay(t *testing.T) { } err = container.Init() - assert.Error(t, err) + assert.NoError(t, err) _, err = container.Serve() assert.Error(t, err) diff --git a/tests/psr-worker-bench.php b/tests/psr-worker-bench.php index ef741a61..d0c72eae 100644 --- a/tests/psr-worker-bench.php +++ b/tests/psr-worker-bench.php @@ -45,13 +45,14 @@ if ($env->getMode() === 'http') { $worker = $factory->newWorker('default'); // register all workflows - foreach ($getClasses(__DIR__ . '/../temporal/Workflow') as $name) { - $worker->registerWorkflowType('Temporal\\Tests\\Workflow\\' . $name); + foreach ($getClasses(__DIR__ . '/src/Workflow') as $name) { + $worker->registerWorkflowTypes('Temporal\\Tests\\Workflow\\' . $name); } - // register all activity - foreach ($getClasses(__DIR__ . '/../temporal/Activity') as $name) { - $worker->registerActivityType('Temporal\\Tests\\Activity\\' . $name); + // register all activity + foreach ($getClasses(__DIR__ . '/src/Activity') as $name) { + $class = 'Temporal\\Tests\\Activity\\' . $name; + $worker->registerActivityImplementations(new $class); } $factory->run(); diff --git a/tests/src/Activity/SimpleActivity.php b/tests/src/Activity/SimpleActivity.php new file mode 100644 index 00000000..576b126e --- /dev/null +++ b/tests/src/Activity/SimpleActivity.php @@ -0,0 +1,63 @@ +<?php + +namespace Temporal\Tests\Activity; + +use Temporal\Activity\ActivityInterface; +use Temporal\Activity\ActivityMethod; +use Temporal\Api\Common\V1\WorkflowExecution; +use Temporal\DataConverter\Bytes; +use Temporal\Tests\DTO\Message; +use Temporal\Tests\DTO\User; + +#[ActivityInterface(prefix: "SimpleActivity.")] +class SimpleActivity +{ + #[ActivityMethod] + public function echo( + string $input + ): string { + return strtoupper($input); + } + + #[ActivityMethod] + public function lower( + string $input + ): string { + return strtolower($input); + } + + #[ActivityMethod] + public function greet( + User $user + ): Message { + return new Message(sprintf("Hello %s <%s>", $user->name, $user->email)); + } + + #[ActivityMethod] + public function slow( + string $input + ): string { + sleep(2); + + return strtolower($input); + } + + #[ActivityMethod] + public function sha512( + Bytes $input + ): string { + return hash("sha512", ($input->getData())); + } + + public function updateRunID(WorkflowExecution $e): WorkflowExecution + { + $e->setRunId('updated'); + return $e; + } + + #[ActivityMethod] + public function fail() + { + throw new \Error("failed activity"); + } +}
\ No newline at end of file diff --git a/tests/src/Client/StartNewWorkflow.php b/tests/src/Client/StartNewWorkflow.php new file mode 100644 index 00000000..67bc1d01 --- /dev/null +++ b/tests/src/Client/StartNewWorkflow.php @@ -0,0 +1,23 @@ +<?php + + +namespace Temporal\Tests\Client; + +use Temporal\Client; +use Temporal\Tests\Workflow\SimpleDTOWorkflow; + +use function Symfony\Component\String\s; + +class StartNewWorkflow +{ + private $stub; + + public function __construct(Client\ClientInterface $client) + { + $this->stub = $client->newWorkflowStub(SimpleDTOWorkflow::class); + } + + public function __invoke() + { + } +} diff --git a/tests/src/Workflow/SagaWorkflow.php b/tests/src/Workflow/SagaWorkflow.php new file mode 100644 index 00000000..e47c0203 --- /dev/null +++ b/tests/src/Workflow/SagaWorkflow.php @@ -0,0 +1,54 @@ +<?php + +/** + * This file is part of Temporal package. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Temporal\Tests\Workflow; + +use Temporal\Activity\ActivityOptions; +use Temporal\Common\RetryOptions; +use Temporal\Tests\Activity\SimpleActivity; +use Temporal\Workflow; + +#[Workflow\WorkflowInterface] +class SagaWorkflow +{ + #[Workflow\WorkflowMethod(name: 'SagaWorkflow')] + public function run() + { + $simple = Workflow::newActivityStub( + SimpleActivity::class, + ActivityOptions::new() + ->withStartToCloseTimeout(60) + ->withRetryOptions(RetryOptions::new()->withMaximumAttempts(1)) + ); + + $saga = new Workflow\Saga(); + $saga->setParallelCompensation(true); + + try { + yield $simple->echo('test'); + $saga->addCompensation( + function () use ($simple) { + yield $simple->echo('compensate echo'); + } + ); + + yield $simple->lower('TEST'); + $saga->addCompensation( + function () use ($simple) { + yield $simple->lower('COMPENSATE LOWER'); + } + ); + + yield $simple->fail(); + } catch (\Throwable $e) { + yield $saga->compensate(); + throw $e; + } + } +} |